您的位置:首页 > 编程语言 > Python开发

[python] 0x3 Python Tutorial: Fuzzer

2015-09-16 14:03 323 查看
Fuzzer的作用就是发送不同数量的输入,尝试使得应用程序崩溃。

首先看一个fuzzer的伪代码

<import modules> #most likely will be socket, sys, but if its a web service you might import httplib,urllib,etc.

#Set up remote IP/Port variables
#Invoke the script: ./script.py <RHOST> <RPORT>
RHOST = sys.argv[1]
RPORT = sys.argv[2]

#Define your buffer string that will be incremented and send the buffer
buffer = '\x41'*50

#Create a loop that will connect to the service and send the buffer:
while True:
try:
#send buffer
#increment buffer by 50
buffer = buffer + '\x41'*50
except:
print "Buffer Length: "+len(buffer)
print "Can't connect to service...check debugger for potential crash"


下面的代码是测试ftp的

#Import the required modules the script will leverage
#This lets us use the functions in the modules instead of writing the code from scratch
import sys,socket
from time import sleep

#set first argument given at CLI to 'target' variable
target = sys.argv[1]
#create string of 50 A's '\x41'
buff = '\x41'*50

# loop through sending in a buffer with an increasing length by 50 A's
while True:
#The "try-except" catches the programs error and takes our defined action
try:
# Make a connection to atrget system on TCP/21
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.settimeout(10)
s.connect((target,21))
s.recv(1024)

print "Sending buffer with length: "+str(len(buff))
#Send in string 'USER' + the string 'buff'
s.send("USER "+buff+"\r\n")
s.close()
sleep(1)
#Increase the buff string bu 50 A's and then the loop continues
buff = buff + '\x41'*50
except:#If we fail to connect to the server,we assume its crashed and print the statement below
print "[+] Crash occured with buffer length: "+str(len(buff)-50)
sys.exit()


程序的运行过程如下:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: