Slashdot Mirror


How to Crack a Website - XSS, Cookies, Sessions

twistedmoney45 writes "Informit.com provides an insiders look at a real life XSS attack and how it was used to bypass the authentication scheme of an online web application, leading to "shell" access, an admin account, and more. XSS attacks are often discussed in theory — this walk through illustrates just how dangerous these types of attacks can be in reality."

3 of 167 comments (clear)

  1. Re:Ok? by PowerKe · · Score: 5, Informative

    1) A user will go to the bad guy's website
    Well, that's the hard part, but you could even try using an HTML formatted mail.

    2) That the user will have an account on the attacked website
    The place to put the code injection was on the login screen, so it's open for anyone. You could hide the login page in an invisable iframe.

    3) That said user will want to log into the attacked website right after going to the badguy website?
    The important thing is that the target logs on during the timeframe where the cookie is valid. If you're lucky and the site uses a permanent cookie, you could even take over a login session from days ago. If it's a session cookie you could take over a previous session if the user didn't close his browser after previously using the admin application.

  2. With all due respect by rehashed · · Score: 5, Informative

    This is a perfect example of a shoddily developed website.
    Additionally, it is, in certain respects, a retarded piece of journalism.

    The XSS mentioned requires the use of phishing techniques - why not simply capture username and password and this point of the exercise, it will allow you to regain entry once the session expires, and will allow you to overcome and further validation that the session handler may require.
    The XSS technique itself, printing the value of the cookie data via javascript to perform a get request to the evil server should not occur in the first place. That is simply shoddy website development. Sanitize input, escape output. Its not more difficult than that. Any developer who fails to grasp this most basic concept should not be in that line of work.

    Secondly is the ability to transfer a session. In the example, the attacker utilizes a third party utility to modify the request data. Why he has done this is beyond me - much easier to simply edit the cookie itself, or even pass the session id back as a 'get' request, a tehnique accepted by default on many PHP installs. It is rather basic to overcome this kind of attack by utilizing a more sophisticated session handler, although this is rarely done as it is taken as a given that the attacker is not going to easily obtain a session ID.

    Thirdly, is simple abuse of a poorly designed web application. There is no validation in place to ensure that the user has permission to perform a task on a designated object. In this case, there is no validation to ensure that user 42 has permission to modify data related to user 36. This is simply poorly designed, and again would not happen where a developer has half a clue about what he is doing.

    Finally, is the mother of all attacks - the ability to upload and run abitrary code. This is a combination of two blatantly obvious (to those who are not clueless) issues that should not arise in a professional web application. Firstly, is the ability to upload files of a certain type. Apache, for example, doesnt require PHP files to be marked as executable, it will simply run anything with a .php extension (or others depending on configuration) through the PHP parser. If there is no reason for a user to be able to upload files of this type, basic sanitization should be in place to prevent the upload of these file types, or, more easily only allow files with permissable extensions to be uploaded. The second issue is related to basic site administration, unless there is need for direct access to the files, uploads should be located in a directory outside of the webroot, preventing direct access to (and possible execution of) these documents. If direct access is require, all external handlers should be disabled for that directory by the simple usage of a .htaccess file. This would mean that any uploaded scripts/executables would be treated in the same manner as a regular file, and be downloaded as opposed to 'run'.

    In short, this was a very poorly designed web application. It didnt take into consideration any secure web development practices, such as Sanitization, Validation, Authorization and Limitation.
    Unfortunately, in todays climate, every man and his dog is a web developer, and 99% of them are complete and utter idiots.

  3. Some simple fixes would be sufficient by vdboor · · Score: 5, Informative
    As short summary, what every (PHP) developer should do is:
    • limit the session to the IP-address of the visiting user.
    • use htmlentities() on all outputted HTML
    • secure file uploads to avoid uploading PHP code
    And most important (but not relevant for TFA):
    • use mysql_real_escape_string() on all database input, or better: the variable binding feature of PEAR::DB
    • disable register_globals, use $_GET, $_POST and $_COOKIE instead.
    • Use preg_replace( '/[^a-zA-Z0-9\-_]', '', $input ) on all input used in file names.
      Things like require_once("files/" + $input + ".html") actually read php files when it's called as ?input=file.php%00
    --
    The best way to accelerate a windows server is by 9.81 m/s2 ;-)