Skip to main content

Posts

Showing posts from 2012

Data leakage in JSON

A web application is sending data in this format: {"t":1,"p":1,"r":1,"rows":[{"i":0,"c":["n","H, C","A","5","T","n"]}]} this is a valid JSON, before moving on lets understand an important concept: 1. Javscript expression 2. javascript statement javscript expressions are not executed by javascript parser, but statements are: for ex: <script> {"t":1,"p":1,"r":1,"rows":[{"i":0,"c":["n","H, C","A","5","T","n"]}]} </script> this will not be executed, that is, objects won't be created. The above example is for a javascript expression. But now when it is converted into a statement as given below: <script> [{"t":1,"p":1,"r":1,"rows":[{"i":0,"c":[&qu

Setting default encoding to UTF-8 in Python

After a long struggle for fixing up an error thrown by my Python script, I finally figured out an easy way to do it. As we know, Python's default encoding is ASCII (0-127), anything beyond that , Non-ASCII characters throws UnicodeEncode exception. To fix it up, we need to use UTF-8 encoding, which suits most of the characters. The easiest way to do that is: Go to your Python setup directory and then go to lib: C:\Python27\lib Look for site.py file, used for site specific configuration Edit it: Go to 'setencoding()' function and change the line: encoding = "ascii" to encoding = "utf-8" That's it! I don't know other implications of editing it right in site.py file but it worked for me, and I found it the easiest way to change the encoding!

URL rewriting and CSRF

Is url rewriting a mitigation of CSRF? Though, almost sure it's not a foolproof solution, I put up this query before all security gurus out there on webappsec. The application in question was replacing all the urls with some randomized and unique long strings in this format: https://mysite.com/myportal/b1/04_SjzQ0NTYyNzS2MLTUj9CPykssy0xPLMnMz0vMAfGjzOJDfU19LNxMTQwsAoydDDyNXb0cnc2dDA2czfRzoxwVAVLe6h0!/ The url was long enough and sufficiently randomized. The argument in favor of randomized url as csrf mitigation is, even an attacker is able to grab the url, it won't be valid for next session. So, the attacker can't exploit it by sending/ embedding in link/ images etc as it would stand invalid. Thus csrf mitigated. But let's consider the scenario wherein an attacker goes to logged in victim's machine, applied his social engineering tricks and note down the url , convince user to click the forged link sent to him. If the user stays at the same page, he gets exploited

SQL Injection in search field

Earlier I had written about performing SQL injection in search field and how to do a DoS attack and privilege escalation using 'Like' operators. Now another SQLi exploitation I came across recently. That too in the search field. This becomes important as lots of people don't pay much attention on the search forms/ fields in the application. My aim is to show that a search form can also be exploited with SQL Injection. The following queries are based on a real world exploitation. The steps and data are for just illustration purpose only. Suppose, the search form provides the details of users who have accessed the application some time and their login time details etc, we just need to provide their name in the search box provided. All the data were being going as Post request. So, to just fingerprint the database, I provide, 'nil'+'esh' in the search field and it successfully gives me the results. That means the database behind the application is conca

Android Penetration Testing

Published in Hakin9 Extra Magazine.  " In this article we’ll discuss about steps involved in performing security assessment of an Android based application. We will see use of various tools and methodologies. There are various other methods and tools but steps are very common in nature..." It can be downloaded here .

Python script to mail merge with CC

Limitation of normal mail merge is that you can't insert Cc/Bcc fields into it. I have tried to overcome this by writing a small script. The script takes the recipients in To and recipients in Cc fields from an excel sheet . It reads the sheet one by one from both columns and send them emails reading on the contents from an external fields. Yes, it's simple, but what I was trying earlier was something else. I was trying to send 'personalized' emails with 'Cc' field in the mail. But the 'personalized' part is very difficult to implement, as I was not able to write the variable data to the body of the email. So, settled down with this fixed body contents being read from external file. Let me know if anybody is aware of how to send personalized body contents to respective users. I mean the some fields in the body of the mail should on user basis. In this case the body of the mail is general and fixed in nature. Code to read user lists from excel and s

Nipper Download

The great open source Nipper tool, used for auditing infrastructure and network devices, has now become commercial. So visiting http://sourceforge.net/projects/nipper/ would give you the latest version (1.0) which is of little help, as it contains the stripped version. So, no use of it. Fortunately, my friends on Null suggested me few links from where still the older version (0.11-12) could be downloaded. One of such link is: http://tools.l0t3k.net/NETWORKutils/ , you can download  nipper-inone-0.12.6.zip. It's an exe and you can run it directly. Alternate method: Upgrade to BackTrack5 R2. The latest version includes the Nipper-ng tool. To update to the latest version: http://www.backtrack-linux.org/backtrack/upgrading-to-backtrack-5-r2/  Also, once upgraded you need to install Nipper on the new kernel: apt-get install nipper-ng Screenshot from BT5 R2:

Andorid Security Assessment

Recently I got a chance to do security assessment of an Android-based app. As the Internet is full of the methods of doing Android assessment, here I shall try to list down major steps to perform it. For Intercepting traffic: 1. Download the Android SDK tool from http://developer.android.com/sdk/index.html. It includes SDK and AVD (Android Virtual Device). They are necessary for creating the VM and installing emulator. 2. Once, emulator started, install the android app's .apk file on it.  3. Configure local web proxies, eg Burp, Paros to intercept the traffic by modifying the Internet setting in Android by Settings->Wirless & Network Settings-> Mobile Networks -> Access Point Names-> Proxy Name(PC's IP address) & Port. 4. Now we may perform the assessment as we do for normal web application. Code review of the app: 1. Rename the .apk file to .zip file and extract it. You'll find classes.dex file which can be converted into a jar file us

My Article on Disk Forensics

Published in Hakin9 Extra Magazine. "Complete description of tools and their uses are out of scope of this article, we’ll be just using them for our forensics, as you may get a fair idea about them during our process. We shall be using BackTrack(BT) for our analysis. You could pretty much use any distro available as all have mostly common necessary tools. You could use any normal Linux _avors such as Fedora, RedHat, Ubuntu as well, but the advantage of using distros like BT is that they already have a fair collection of these tools, otherwise you may need to install them." Can be downloaded here .

Bypassing XSS filter in alert msg box

Chintan, Ronnie and I were discussing about one issue regarding how to bypass a specific XSS filter in alert message box. We were unable to breakout. Chintan's problem statement was: I am running into one issue with XSS and was interested if there is any way I can bypass it. Following the response code where user supplied input is embedded. Input is taken via a text box. <script type="text/javascript">alert(' No Information is found for the card 1 ');script> User supplied input 1 is highlighted in red. I am trying to break out of this alert box, however when a single quote is given as input, the output is escaped using a backslash. It is as follows: Input:      1' Output: < script type = "text/javascript" > alert(' No Information is found for the card 1\'' ); script > I am using IE 8 and tried using back ticks just to check if I can get around this limitation, however it did not work. Any sugg

Closing PPTP on 1723

To know about PPTP go to : http://en.wikipedia.org/wiki/Point-to-Point_Tunneling_Protocol  Basically PPTP is used as method to connect and implement VPN (Virtual Private Networks). There have been other protocols as well for example, IPSec. PPTP has been often criticized for its well known vulnerabilities, like weak encryption etc. But I am not concerned with all these, my challenge was to explore the ways to close the PPTP(Port 1723) on a machine (Windows XP). I did a lot of googling around on the web for hours but was unable to find any satisfying solution. Most results were related to how to setup a VPN connection using PPTP on a Windows client machine. But my question was how to close port 1723 (PPTP), if already your machine is acting as VPN server? So, I started other way round. I setup my machine as a VPN server. Steps are very simple: 1. Go to Network connections 2. Click on "Create a new connection" wizard 3. Select "Set up an advanced connection&quo

Breaking Excel password protection

If you came across an excel sheet asking for password for allowing to make any changes into it, you may want to unprotect it. All we need to do is to edit the xml file which comes intrinsically packaged with Excel 2007 or 2010. But what about Excel 2003? For that, open the Excel 2003 file within Excel 2007, save it as xlsx file. So, keep in mind all the Excel files below 2007 version, you need to convert them as Excel 2007 with extension .xlsx. Now here are the steps for doing that: 1. Open the Excel 2003 file (e.g. Secret.xlsx) and save it as .xlsx (Excel 2007) format. If you already have Excel 2007 file, then no need for any conversion. 2. Now change the extension of the above file to .zip and extract the zipped file. Browse through the file in the extracted folder and go to: <LocalPath>\Secret\xl\worksheets.   3. Now open the sheet/ sheets you want to remove protection in any xml editor. Look for keywords such as 'sheetProtection' or 'workbo

AirPcap on BackTrack5

AirPcap Nx wireless adapter is compatible with BT5. I have heard about the difficulties of recognizing and connecting the AirPcap adapter with BT. But surprisingly for me, the driver is already loaded in BT5! So just connect the device and enjoy! carl9170 is the name of the driver already loaded into BT5. Starting the card into monitor mode: The monitor mode mon0 started: Enjoy!

Secure Forgot Password Implemantion

I got a message from Mae Bualat about secure implementation of forgot password mechanism. Although, his way also sounded secure to me, I suggested him more alternatives. It's always arguable the approaches, but these are my personal arguments as per my limited knowledge. Following is the communication between us: Hi Mr. Nilesh Kumar, I've come across your blog while looking for some references on the web for a secured password recovery scheme. I suppose, as a security specialist, you may have inputs to help me work on it. Am looking for a secure password recovery implementation. The process that I am looking into is this: user will need to supply email address used on account registration then birthday, then user will need to supply new password, then the system will send a verification link to his registered email to finalize and confirm the process.But aside from this, am still currently looking for some ways to securely implement this process. Any idea will be

MHTML files

Today my colleague Surendra had a query regarding a weird popup coming up while he was trying to access a website. Although even, I was not very familiar with the kind of message he was getting. All we wanted to know, if it's really anything malicious! He was trying to access some page, and the website was making some weird request to the webserver in order to load some object (here it was a calender) from the server: mhtml:http://abc.com/resources/Calnder.mht The warning message was like this: Even I had not noticed like anything in the past, I did a little research on the topic. The browser was trying to load some MHTML page.MHTML is simply a MIME HTML format, used to combine all the external resources, which are generally loaded as external link, with HTML code into a single file. Generally this file has extension as .mht. So any .mht file contains mix of HTML code and other objects such as, Flash, images, applets, audio files etc. The content of .mht