Skip to content

Commit

Permalink
Update shellcode command/function: replace print by msg, add auto com…
Browse files Browse the repository at this point in the history
…pletion options
  • Loading branch information
longld committed Oct 7, 2012
1 parent da54892 commit 7303f13
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 16 deletions.
13 changes: 9 additions & 4 deletions lib/shellcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import socket
import struct
import httplib
from utils import msg, error_msg

shellcode_x86_linux = {
"exec": (
Expand Down Expand Up @@ -281,12 +282,14 @@ def search(self, keyword):
if keyword is None:
return None
try:
msg("Connecting to shell-storm.org...")
s = httplib.HTTPConnection("shell-storm.org")
s.request("GET", "/api/?s="+str(keyword))
res = s.getresponse()
data_l = res.read().split('\n')
except:
print "Can't connect to shell-storm.org"
error_msg("Cannot connect to shell-storm.org")
return None

data_dl = []
for data in data_l:
Expand All @@ -310,20 +313,22 @@ def display(self, shellcodeId):
return None

try:
msg("Connecting to shell-storm.org...")
s = httplib.HTTPConnection("shell-storm.org")
except:
print "Can't connect to shell-storm.org"
error_msg("Cannot connect to shell-storm.org")
return None

try:
s.request("GET", "/shellcode/files/shellcode-"+str(shellcodeId)+".php")
res = s.getresponse()
data = res.read().split("<pre>")[1].split("<body>")[0]
except:
return -1
error_msg("Failed to download shellcode from shell-storm.org")
return None

data = data.replace("&quot;", "\"")
data = data.replace("&amp;", "&")
data = data.replace("&lt;", "<")
data = data.replace("&gt;", ">")
return data

35 changes: 23 additions & 12 deletions peda.py
Original file line number Diff line number Diff line change
Expand Up @@ -5323,8 +5323,8 @@ def shellcode(self, *arg):
Generate or download common shellcodes.
Usage:
MYNAME generate [arch/]platform type [port] [host]
MYNAME search keyword
MYNAME display shellcodeId
MYNAME search keyword (use % for any character wildcard)
MYNAME display shellcodeId (shellcodeId as appears in search results)
For generate option:
default port for bindport shellcode: 16706 (0x4142)
Expand Down Expand Up @@ -5379,29 +5379,40 @@ def list_shellcode():
text += ")"
msg(text)

# search shellcodes on shell-storm.org
elif mode == "search":
if keyword is None:
self._missing_argument()

res_dl = Shellcode().search(keyword)
if res_dl is None:
print "Need keyword"
if not res_dl:
msg("Shellcode not found or cannot retrieve the result")
return
print "%s\t%s" %(blue("ScId"), blue("Title"))

msg("Found %d shellcodes" % len(res_dl))
msg("%s\t%s" %(blue("ScId"), blue("Title")))
text = ""
for data_d in res_dl:
print "[%s]\t%s - %s" %(yellow(data_d['ScId']), data_d['ScArch'], data_d['ScTitle'])
text += "[%s]\t%s - %s\n" %(yellow(data_d['ScId']), data_d['ScArch'], data_d['ScTitle'])
pager(text)

# download shellcodes from shell-storm.org
elif mode == "display":
if to_int(shellcodeId) is None:
self._missing_argument()

res = Shellcode().display(shellcodeId)
if res is None:
print "Need shellcode id"
return
elif res == -1:
print "Shellcode id not found"
if not res:
msg("Shellcode id not found or cannot retrieve the result")
return
print res

msg(res)

else:
self._missing_argument()

return
shellcode.options = ["generate", "search", "display"]

def gennop(self, *arg):
"""
Expand Down

0 comments on commit 7303f13

Please sign in to comment.