-
Notifications
You must be signed in to change notification settings - Fork 58
Fix case of 'Rename-Lesson' to 'rename-lesson' #6
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
base: main
Are you sure you want to change the base?
Changes from all commits
5b024bf
b4ffed8
f18d5fb
ed2e119
6f20adf
612f743
57a56d8
56374f8
fe9cc29
57fc7cf
f04617d
ea014ff
d18eecc
430e684
f861a1c
578246d
f254edb
b73965b
d8c29c9
16e233e
e1c06c2
327a95e
86a5eb4
ef03362
43cf811
26f0d28
f5a9ba2
520c7a6
c42ec12
72ceece
c73bedd
51446f1
0751100
cd2ca98
829a087
9821d6c
4dbd5e7
708941c
b720c15
ab14e22
10dcef2
7243adb
e038d68
6097e40
111368a
cf429ae
3cb5949
f4bc6f3
77fbed8
8fcaadb
0540e67
b802427
b6136cd
c4b3496
6a3710a
c87dd20
3997968
7a5bdf7
c31f647
039e28f
aa83bd5
6591cd4
1316d3c
080e6e4
3b529c9
009633b
cc9616b
9ff9f2a
b826921
61dcdd1
478a5d4
cb13f89
c7dd15a
139f612
89b0e7a
1779dcd
d53b61d
8626e99
9c4d7e1
d13cd75
b927511
8d6b916
7e06cc4
09ecf35
cd4ab56
76f74c5
4649e19
2de815a
1db1f64
c996354
103964e
c2f9fd0
be76efa
d391673
f847664
c2db199
f35fdbe
38eaa28
2b50bc3
f57e7ea
d8852f0
e94a40d
1b62d8d
b78eda1
b7958a2
bd569bd
b305ef9
5ce7ed4
2133398
a5a7783
4e09cdc
49050fb
cfe526e
13314b5
2867d80
70e2510
588d84f
011b69c
b1cecf2
ac05489
7ede3f1
1552b18
a5ce2b2
f0fe47d
73923cd
35bda5c
cd12533
ef5cc9d
d17fab1
0de181e
f45040f
6fdc019
4e2d7ee
dd2d8c1
7486f35
fd22e41
b968b63
b9d2816
9323067
a82a779
bc6182f
8535198
d9cd06f
1b47d9a
0f6d2fc
a1a5246
2b8a3d5
6e5076a
b7fe769
35845e1
2d9b8df
e25dd11
e9ea07b
de77d0a
2e74808
847c5d0
7fd1385
798475d
477a052
83c4c3e
f16dd50
dfe7dcb
bd31eec
dca9964
1cc93fa
083ab82
8869c7b
3f5a7f1
ad2c6c5
8bf93e8
e09d89a
83587fd
e1757ab
729d49c
7591b3e
93730ea
f179d52
d70f7ef
8f994fd
884c23d
8c79283
c00a268
d1d163c
dbda5b7
dfbfb0d
22ed410
dd15ef5
b011e68
6c920a1
3e5331a
b818ce5
450fcbc
5d55d65
f17cb48
6c45fa7
f6a1ca6
98134c3
1d37669
27b050c
9a9e94f
855eeaf
a5fbecc
fe69139
7195160
fc97a8a
6623f0c
d16cca5
7eda09b
8f89d5c
8817fba
0a5f93d
064403c
9be7974
bdf1197
2bc4a2c
5458d6f
3075479
f36224f
9e2a608
be34946
2a4e822
574a53a
e6cde00
b0be680
6ecbfde
1276327
7cd3d0b
04f875e
873e1dc
fdbff6c
6c36d52
c0320f0
7a8f93e
593a40f
b777c15
f1ba626
44e133f
145d955
48c8003
7e142cb
e39c16e
fc4110f
b4ddefe
21fa28f
9dce09d
27f1e6c
858e688
f3d6fcb
e5baf1c
f256f53
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,8 @@ | ||
| id: example | ||
| name: Example Dojo | ||
| name: Introduction to Reverse Engineering | ||
| type: example | ||
| award: | ||
| emoji: 😀 | ||
| emoji: 🔓 | ||
| image: pwncollege/challenge-simple | ||
| modules: | ||
| - id: hello | ||
| - id: world | ||
| - id: demo | ||
| - id: re-intro | ||
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| #!/usr/local/bin/python | ||
|
|
||
| # IMPORTS | ||
| import os | ||
| import shutil | ||
| import subprocess | ||
|
|
||
|
|
||
| # DECLARATIONS | ||
| # challenge/ Files Declarations | ||
| c_file = "source.c" | ||
| script = "Autoscript.py" | ||
| executable = "executable" | ||
| check_xml = "CheckXML.py" | ||
| addresses_file = "addresses.txt" | ||
| zip_name = "ghidra_11.4.2_PUBLIC_20260324_AutoScripting.zip" | ||
| tool_config = "_auto_start.tcd" | ||
|
|
||
| # Directory Declarations | ||
| curr_dir = os.path.dirname(os.path.abspath(__file__)) | ||
| script_dir = "/home/hacker/ghidra_scripts" | ||
| ext_dir = "/home/hacker/.config/ghidra/ghidra_11.4.2_NIX/Extensions" | ||
| tools_dir = "/home/hacker/.config/ghidra/ghidra_11.4.2_NIX/tools" | ||
|
|
||
| # challenge/ Files Path Declarations | ||
| c_path = os.path.join(curr_dir, c_file) | ||
| script_path = os.path.join(curr_dir, script) | ||
| executable_path = os.path.join(curr_dir, executable) | ||
| check_xml_path = os.path.join(curr_dir, check_xml) | ||
| addresses_file_path = os.path.join(curr_dir, addresses_file) | ||
| zip_path = os.path.join(curr_dir, zip_name) | ||
| tool_path = os.path.join(curr_dir, tool_config) | ||
|
|
||
| # Tool Path Declarations | ||
| gcc_path = "/run/dojo/bin/gcc" | ||
| nm_path = "/run/dojo/bin/nm" | ||
| unzip_path = "/run/dojo/bin/unzip" | ||
|
|
||
| # Destination Path Declarations | ||
| script_destination = os.path.join(script_dir, script) | ||
| tool_destination = os.path.join(tools_dir, tool_config) | ||
|
|
||
| # Command Declarations | ||
| c_compile = [gcc_path, c_path, "-o", executable_path] | ||
| nm_command = [nm_path, executable_path] | ||
| unzip_command = [unzip_path, "-o", zip_path, "-d", ext_dir] | ||
|
|
||
|
|
||
| # CHALLENGE SETUP | ||
| # Create extensions/ if it does not exist in user settings and then unzip extension into it to install extension and plugin | ||
| os.makedirs(ext_dir, exist_ok=True) | ||
| subprocess.run(unzip_command, check=True) | ||
|
|
||
| # Copy the script into ghidra_scripts | ||
| shutil.copy2(script_path, script_destination) | ||
| os.chmod(script_destination, 0o444) | ||
|
|
||
| # Copy the tool config into tools | ||
| shutil.copy2(tool_path, tool_destination) | ||
|
|
||
| # Compile the C file to get the executable | ||
| subprocess.run(c_compile, check=True) | ||
|
|
||
| # Use nm to get the addresses of the variable and function that need to be renamed, and write those to a file for the script to read | ||
| nmOutput = subprocess.run(nm_command, check=True, capture_output=True, text=True) | ||
| nmStdout = nmOutput.stdout | ||
|
|
||
| targets = {"global_target", "functiontarget"} | ||
| nm_addresses = {} | ||
|
|
||
| for line in nmStdout.splitlines(): | ||
| parts = line.split() | ||
|
|
||
| if len(parts) == 3: | ||
| addr, sym_type, name = parts | ||
| if name in targets: | ||
| nm_addresses[name] = "0010" + format(int(addr, 16), "x")[-4:] | ||
|
|
||
| global_targ_address = nm_addresses.get("global_target") | ||
| func_targ_address = nm_addresses.get("functiontarget") | ||
|
|
||
|
|
||
| with open(addresses_file_path, "w") as f: | ||
| f.write(f"{global_targ_address}\n") | ||
| f.write(f"{func_targ_address}\n") | ||
|
|
||
|
|
||
|
|
||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| #@runtime Jython | ||
|
|
||
| from ghidra.framework.model import DomainObjectListener | ||
| from ghidra.app.util.exporter import XmlExporter | ||
| from java.io import File | ||
| import subprocess | ||
|
|
||
| addresses_file_path = "/challenge/addresses.txt" | ||
|
|
||
| with open(addresses_file_path, "r") as f: | ||
| VAR_TARGET_ADDR = toAddr(int(f.readline().strip(), 16)) | ||
| FUNC_TARGET_ADDR = toAddr(int(f.readline().strip(), 16)) | ||
|
|
||
| VAR_EXPECTED_NAME = "pwned_var" | ||
| PARAM_EXPECTED_NAME = "pwned_param" | ||
| FUNC_EXPECTED_NAME = "pwnedfunction" | ||
|
|
||
| done_var = False | ||
| done_parameter = False | ||
| done_function = False | ||
|
|
||
| print("In this challenge, you will have to rename several parts of the binary in order to get the flag.") | ||
| print("The first portion of the executable you should rename is the variable 'global_target'. Locate this variable inside of main and rename it to 'pwned_var'.") | ||
|
|
||
| class ProgListener(DomainObjectListener): | ||
| def domainObjectChanged(self, ev): | ||
| global done_var | ||
| global done_parameter | ||
| global done_function | ||
| global listener | ||
|
|
||
| if not done_var: | ||
| sym = currentProgram.getSymbolTable().getPrimarySymbol(VAR_TARGET_ADDR) | ||
| if sym and sym.getName() == VAR_EXPECTED_NAME: | ||
| print("Correct! You can also rename functions just like with variables. Locate the function named 'functiontarget' and rename it to 'pwnedfunction'.") | ||
| done_var = True | ||
| return | ||
|
|
||
| if done_var and not done_function: | ||
| sym = currentProgram.getSymbolTable().getPrimarySymbol(FUNC_TARGET_ADDR) | ||
| if sym and sym.getName() == FUNC_EXPECTED_NAME: | ||
| print("Correct! Finally, just like with variables declared outside of functions, you can also rename function parameters. Locate the parameter of 'pwnedfunction' and rename it to 'pwned_param'.") | ||
| done_function = True | ||
| return | ||
|
|
||
| if done_function and not done_parameter: | ||
| func = currentProgram.getFunctionManager().getFunctionAt(FUNC_TARGET_ADDR) | ||
| if func: | ||
| params = func.getParameters() | ||
| if params and params[0].getName() == PARAM_EXPECTED_NAME: | ||
| print("Correct! You have successfully completed the rename challenge") | ||
| done_parameter = True | ||
|
|
||
| currentProgram.removeListener(listener) | ||
|
|
||
| program = getCurrentProgram() | ||
| exporter = XmlExporter() | ||
| output_file = File("/tmp/rename_challenge_completed.xml") | ||
| exporter.export(output_file, program, None, getMonitor()) | ||
|
|
||
| result = subprocess.Popen( | ||
| ['/challenge/CheckXML.py'], | ||
| stdout=subprocess.PIPE, | ||
| stderr=subprocess.PIPE | ||
| ) | ||
| out, err = result.communicate() | ||
| out = out.strip() | ||
|
|
||
| if out == "INCORRECT": | ||
| print("Something was not renamed correctly. Please try again.") | ||
|
|
||
| else: | ||
| print(out) | ||
|
|
||
| return | ||
|
|
||
| listener = ProgListener() | ||
| currentProgram.addListener(listener) | ||
| print("Monitoring: " + currentProgram.getName()) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| #!/usr/bin/exec-suid -- /usr/local/bin/python -I | ||
| import os | ||
|
|
||
| curr_dir = os.path.dirname(os.path.abspath(__file__)) | ||
| addresses_file_path = os.path.join(curr_dir, "addresses.txt") | ||
|
|
||
| global_target_addr = "" | ||
| function_target_addr = "" | ||
|
|
||
| with open(addresses_file_path, "r") as f: | ||
| global_target_addr = f.readline().strip() | ||
| function_target_addr = f.readline().strip() | ||
|
|
||
| edited_global = f"SYMBOL ADDRESS=\"{global_target_addr}\" NAME=\"pwned_var\" NAMESPACE=\"\" TYPE=\"global\" SOURCE_TYPE=\"USER_DEFINED\" PRIMARY=\"y\"" | ||
| edited_function = f"SYMBOL ADDRESS=\"{function_target_addr}\" NAME=\"pwnedfunction\" NAMESPACE=\"\" TYPE=\"global\" SOURCE_TYPE=\"USER_DEFINED\" PRIMARY=\"y\"" | ||
| edited_param = "REGISTER_VAR NAME=\"pwned_param\" REGISTER=\"EDI\" DATATYPE=\"undefined4\" DATATYPE_NAMESPACE=\"/\"" | ||
|
|
||
| global_edited = False | ||
| function_edited = False | ||
| param_edited = False | ||
|
|
||
| with open("/tmp/rename_challenge_completed.xml", "r", encoding="UTF-8") as file: | ||
| for line in file: | ||
| if edited_global in line: | ||
| if(not global_edited): | ||
| print("Global variable renamed correctly!") | ||
| global_edited = True | ||
| if edited_function in line: | ||
| if(not function_edited): | ||
| print("Function renamed correctly!") | ||
| function_edited = True | ||
| if edited_param in line: | ||
| if(not param_edited): | ||
| print("Parameter renamed correctly!") | ||
| param_edited = True | ||
| if global_edited and function_edited and param_edited: | ||
| break | ||
|
|
||
| #print("euid:", os.geteuid()) | ||
| if global_edited and function_edited and param_edited: | ||
| with open("/flag", "r") as flag: | ||
| print(flag.read()) | ||
| else: | ||
| print("INCORRECT") |
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.
The PR title/intent suggests a case-only rename of a single lesson directory, but the diff shows a major dojo restructuring (module list rewired, sample modules removed) plus large third-party/vendor drops. If the intent really is only the case normalization, this PR should be split so the case rename is isolated from dojo/module and vendored Ghidra content changes.