MCPcopy Create free account
hub / github.com/longld/peda / Shellcode

Class Shellcode

lib/shellcode.py:239–384  ·  view source on GitHub ↗

Simple wrapper for pre-defined shellcodes generation For complete and advanced shellcodes, Metasploit is recommended

Source from the content-addressed store, hash-verified

237SHELLCODES = {"x86": shellcode_x86}
238
239class Shellcode():
240 """
241 Simple wrapper for pre-defined shellcodes generation
242 For complete and advanced shellcodes, Metasploit is recommended
243 """
244 def __init__(self, arch="x86", platform="linux"):
245 if arch in SHELLCODES and platform in SHELLCODES[arch]:
246 self.shellcodes = SHELLCODES[arch][platform].copy()
247 else:
248 self.shellcodes = None
249
250 @staticmethod
251 def gennop(size, NOPS=None):
252 """
253 genNOP is used to create an arbitrary length NOP sled using characters of your choosing.
254 Perhaps you prefer \x90, perhaps you like the defaults. Given a list of NOP characters,
255 genNOP will randomize and spit out something not easily recognized by the average human/rev engineer.
256 Still, while you are working a vulnerability, you may prefer to specify one byte such as "A" or
257 "\x90" as they are easily identified while searching memory.
258 Defaults:
259 # inc eax @ \x40
260 # inc ecx A \x41
261 # inc edx B \x42
262 # inc ebx C \x43
263 # inc esp D \x44
264 # inc ebp E \x45
265 # inc esi F \x46
266 # inc edi G \x47
267 # dec eax H \x48
268 # dec esx J \x4a
269 # daa ' \x27
270 # das / \x2f
271 # nop \x90
272 # xor eax,eax \x33\xc0
273 source: atlasutils
274 """
275 DEFAULT_NOPS = "ABCFGHKIJ@'"
276 if (not NOPS):
277 NOPS = DEFAULT_NOPS
278 sled = ""
279 for i in range(size,0,-1):
280 N = random.randint(0,len(NOPS)-1)
281 sled += NOPS[N]
282 return sled
283
284 def shellcode(self, sctype, port=None, host=None):
285 if not self.shellcodes or sctype not in self.shellcodes:
286 return None
287
288 if port is None:
289 port=16706
290 if host is None:
291 host='127.127.127.127'
292
293 shellcode = self.shellcodes[sctype]
294 try:
295 port = struct.pack(">H", port)
296 addr = socket.inet_aton(host)

Callers 1

shellcodeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected