I sent it to article in Pentest Magazine first, but now I'm working on better version, so maybe this one will help somebody :)
Idea is simple: do some 'grep' tricks, and write it as an output.html :)
# ---------------------------------------------------
# knewme.py @ 2o11 - v3
# ---------------------------------------------------
# This is a sample 'dirty hack' for php src audit.
#
# dated :
# xx.o9.2o11 + ...?
# 28.o9.2o11 + php files 'founded'
# 27.o9.2o11 + output.html
# + project started
#----------------------------------------------------
# run: python knewme.py /dir/with/files/in/php/
# hf o/
#
import sys # arg
import glob # list files end elemIT
import getopt # opts implementation
# --------------------------------------------------
# argvs
try:
opts, args = getopt.getopt(sys.argv[1:], "hdf:v", ["help","dir=","file="])
except getopt.GetoptError, err:
print str(err)
print "Ups... ;C Try with -h;)"
sys.exit(2)
verbose = False
for o, a in opts:
if o == "-v":
verbose = True
elif o in ("-h","--help"):
print ""
print "\t-----------------------------"
print "\t[<>] knewme.py @ 2o11.v3 [<>]"
print "\t-----------------------------"
print "try this way:"
print "\t-d /dir/where/you/wanna/find/phps"
print "\t-f /dir/where/is/your/file.php"
print "\t-h thats me!"
print "\n[~] try again ;)"
elif o in ("-d","--dir"):
path = sys.argv[2] +"*.php" # updated by glob() 28.o9 to find .phps
logfile = open('dir_check.log','w')
for stri in glob.glob(path):
log = logfile.write(stri) # ---| these 2 lines log to file $logfile
log = logfile.write("\n") # ---|
logfile.close()
print ("[+] List of php files founded at "+path+" are noted in [dir_check.log]")
print "[i] You should test it manualy now."
sys.exit()
elif o in ("-f","--file"):
path = sys.argv[2] # = argv[1]
filek = open(path, 'r') # read mode
stri = filek.readlines() #
filek.close() # close the file (its already 'readed'
print " <html><head><title> KnewMe Project @ 2011 - This is Your Rerport</title></head>"
print " <body><br>"
print " <center><b><h1> KnewMe Project @ 2011 <br></b><center></h1>"
print "<b><p align=\"left\"><br>[+] Now checking file: ", filek.name
print "</b>"
vulnlist = open('vuln.php_list','r')
for vulnline in vulnlist:
print ("<b><p align=\"left\">[+] Possible vulnerable function name is : <font color=\"red\"> "+vulnline+" </font> </p></b>")
i=1
v = vulnline.strip()
for line in stri: # for $line.find(?) in str=filedsk
if line.find(v) != -1:
print ""
print " <table border=\"1\">"
print " <tr bgcolor=\"teal\">"
print " <th>line</td><td>check this</th>"
print " </tr><tr bgcolor=\"white\">"
print (" <td> %d </td><td> %s </td>") % (i,line)
print "<br>"
print " </tr>"
print " </table>"
print "</body></html>"
i+=1
# ----------------------------------------------------------- end of for...
print "<b>---------------[ END of this test HERE ] ---------------</br>"
# --------------------------------------------------------------------end of for...
# print ""
# print "[+] vulnerable function list : vuln.php_list"
# print ""
# -- end of last elif
else:
assert False, "unhandled option"
I will be glad if it helps someone to better understand Python :)
If You have any questions, feel free to ask.
No comments:
Post a Comment
What do You think...?