Skip to content

Commit 634e269

Browse files
committed
copy over web/rev guides
1 parent 4d12999 commit 634e269

19 files changed

+234
-1
lines changed

fallctf-2024/src/SUMMARY.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
- [Intro](./intro.md)
44
- [pwntools](./pwntools.md)
55
- [Misc](./misc.md)
6-
- [CRYPTO](./crypto/crypto.md)
6+
- [Web](./web/web.md)
7+
- [Reverse Engineering](./rev/rev.md)
8+
- [Crypto](./crypto/crypto.md)
79
- [OSINT](./osint/osint.md)
810
- [PWN](./pwn/pwn.md)

fallctf-2024/src/rev/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
See [./rev.org](./rev.org)
250 KB
Loading
433 KB
Loading
96.8 KB
Loading

fallctf-2024/src/rev/rev.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Reverse Engineering
2+
<embed src="./rev.pdf" type="application/pdf" style="width: 100%; height: 80vh;">

fallctf-2024/src/rev/rev.org

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#+title: Reverse Engineering
2+
3+
* Start here
4+
** General tips
5+
- figure out what the goal is
6+
- there is usually a clear "win condition", such as printing a flag
7+
- figure out what the input is
8+
- some parts of the program don't change depending on the input
9+
- it might not matter what the input is!
10+
- how does the input get used?
11+
** A note about past meetings
12+
SIGPwny has already ran two meetings on this topic! Check out [[https://sigpwny.com/meetings/fa2023/2023-09-17/][Reverse Engineering Setup]] and [[https://sigpwny.com/meetings/fa2023/2023-09-21/][Reverse Engineering I]]. We have slides and recorded meeting presentations, which you may prefer more than these notes.
13+
* Basics
14+
** What it is
15+
Reverse engineering is the process of understanding computer programs. The goal is to figure out what the program does. Usually, programs are difficult to understand, either intentionally or unintentionally.
16+
** Main types of analysis
17+
- Static analysis: reading code, using tools to understand code /without running it/
18+
- Good place to start, not great if there's a lot of code
19+
- Dynamic analysis: running code, inspecting or modifying the program as it's running
20+
- Generally faster, captures entire program environment
21+
** A word on abstractions
22+
- Abstract (higher level) programs are easier to understand
23+
- Languages like Python and JavaScript are higher level
24+
- Languages like assembly and C are lower level
25+
- As you modify a program to become more abstract (to better understand it), you lose some information in the process
26+
* Tools
27+
** Bytecode viewer
28+
*** Installation
29+
- see https://github.com/Konloch/bytecode-viewer
30+
*** When to use
31+
This program is used to decompile Java files, which usually have the .jar extension
32+
*** How to use
33+
Simply import the java jar program into the bytecode viewer and see the decompiled java code! This works by recovering the java code from the compiled java bytecode.
34+
** Ghidra
35+
*** Installation
36+
- see [[https://sigpwny.com/meetings/fa2023/2023-09-17/][Reverse Engineering Setup]]
37+
- or, just read the [[https://ghidra-sre.org/InstallationGuide.html][installation guide]]
38+
*** When to use
39+
Use this tool for binaries, not python scripts. Ghidra "decompiles", or simplifies, binary programs into more human-readable "pseudo-C" code.
40+
41+
Ghidra is a *static analysis* tool.
42+
*** Interface
43+
[[./images/ghidra1.png]]
44+
45+
Once you open a program in Ghidra, click "OK" for all the auto analyze popups (there should be several). Now, the interface should look like the above image.
46+
47+
(1) is the decompiled code output. This is what you will be looking at for the most part. You can rename variables by clicking a variable and pressing =L=. Change the type by right clicking and selecting =Retype Variable=.
48+
49+
(2) is the assembly instructions. This won't be very helpful if you don't know assembly, and can be mostly ignored for the challenges at Fall CTF.
50+
51+
(3) is the "symbol tree". This shows you different named values that are present in the file. Click =Functions= and scroll down to select the =main= function. This shows you the first function that runs.
52+
53+
[[./images/ghidra2.png]]
54+
55+
Here we can see the =main= function in the symbol tree. If there is no =main=, click =_start= and see what that function calls.
56+
57+
[[./images/ghdira3.png]]
58+
59+
Above is a picture of the decompilation (disclaimer: this is not a challenge from Fall CTF). Almost every function you see will have an if statement with =__stack_chk_fail= at the bottom. This is a check for the "stack canary", which is not relevant to any challenges here. It may be of more interest in pwn challenge. The ~local_10 = *(long *)(in_FS_OFFSET + 0x28);~ line at the top sets up the stack canary and can also be ignored.
60+
61+
Note that the variables are named with undescriptive names, such as =iVar1= and =local_28=. This is because the decompiler does not know the details of variables in the original function. As a result, it has to generate variable names.
62+
** GDB
63+
*** Installation
64+
- see [[https://sigpwny.com/meetings/fa2023/2023-09-17/][Reverse Engineering Setup]]
65+
*** When to use
66+
Similarly to Ghidra, use this tool for binaries, not python scripts. GDB is a debugger that runs programs, giving you the ability to stop, inspect, and modify code as it is executing.
67+
68+
GDB is a *dynamic analysis* tool.
69+
*** Basics
70+
Run =gdb ./chal= on the command line, where =chal= is the name of the program. Note that you must be on Linux (WSL works too). This will not work for Apple Silicon Mac users.
71+
72+
GDB will launch you into a program with a different terminal prompt, where each line starts with =(gdb)=. You interact with the program by typing in commands
73+
*** Commands
74+
- misc
75+
- =help <command>=: get help about any of the commands listed here
76+
- running
77+
- =run=: run the program from the start
78+
- =quit=: exit GDB
79+
- =start=: start the program and break on the =main= function
80+
- breakpoints
81+
- =break <func>+<offset>=: set a breakpoint at the function =<func>= with an offset =<offset>=. Useful to get the offset from the =disas= command
82+
- inspecting program
83+
- =disas <func>=: disassemble the =<func>= function
84+
- =info reg=: print all the registers
85+
- =x=: print data (see =help x= for more info)
86+
- =x/4gx 0x1234=: print 4 QWORDS (64-bit values) in hex starting at address =0x1234=
87+
- =x/10i $rip=: print 10 instructions starting at =$rip= (current instruction pointer)
88+
- =x/7wx $rsp=: print 7 WORDS (32-bit values) in hex starting at =$rsp= (stack pointer)
89+
- =x/8bd $rdi=: print 8 bytes in decimal starting at the address in =$rdi=
90+
- =set=: set values
91+
- ~set $rax=23~: sets =$rax= to 23
92+
- ~set $rip+=4~: adds 4 to =$rip=
93+
- this skips the current instruction, if it is 4 bytes long
94+
*** General workflow
95+
- first, identify interesting places to set a breakpoint in Ghidra
96+
- use the assembly instructions window in Ghidra to see the offset to break at
97+
- run the program in GDB and set a breakpoint
98+
- modify or print values as desired
99+
- repeat until solved

fallctf-2024/src/rev/rev.pdf

560 KB
Binary file not shown.
63.7 KB
Loading
64.2 KB
Loading
143 KB
Loading
69.2 KB
Loading
395 KB
Loading
357 KB
Loading
184 KB
Loading
144 KB
Loading

fallctf-2024/src/web/images/sql.png

378 KB
Loading
65.4 KB
Loading

fallctf-2024/src/web/web.md

+129
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# Web
2+
3+
We have run two web meeting this semester:
4+
5+
- [Web 1](https://sigpwny.com/meetings/fa2023/2023-09-07/), covering HTML, CSS, and Javascript
6+
- [Web 2](https://sigpwny.com/meetings/fa2023/2023-09-14/), covering SQLi and XSS
7+
8+
9+
## Website Structure
10+
11+
Websites use three main languages: HTML, CSS, and Javascript. HTML is the skeleton of the website, and organizes each of the different elements onto the user's screen. CSS is how you edit and develop the styles on a website. The most important and widely used language within the web is Javascript. Javascript allows you to dynamically change elements within your site, have something happen when a button is pressed, or make a requests to other computers.
12+
13+
## Client-Server Model
14+
15+
When you click on a link within your browser, your computer makes a request to a server located at the address of the link you clicked. This request is then processed on the server's side, and the server sends back the webpage you want to load. This is the Client-Server Model. By manipulating processes within this model's process, you can access extra content on either the server or client side!
16+
17+
When content is sent between your computer and the server, it includes additional metadata called "Headers". Some of this data remains in your browser, either as **cookies** or **local storage** (technically more kinds).
18+
19+
![](./images/network.png)
20+
21+
- Cookies are saved per website, and are sent in each request. They can be changed by Javascript or a request header.
22+
- Local Storage is saved per website, but are not sent in each request. They can be changed by Javascript in your browser.
23+
24+
## Devtools
25+
26+
Developer tools is how you view additional website about an information. For our challenges, we reccommend you download Chrome or Firefox, and not use Safari.
27+
28+
To open devtools, hit `Ctrl + Shift + C` (windows) or `Command + Shift + C` (mac). Alternatively, right click and hit inspect.
29+
30+
![](./images/inspect_context.png)
31+
32+
Chrome Devtools is a suite of software developer information for web development. During challenges, you will be able to poke around different tabs. Here are some helpful tabs to lookout for:
33+
34+
* Console (you can run your own javascript in this tab)
35+
36+
![](./images/console.png)
37+
38+
Pro Tip: You can use breakpoints within the console by clicking next to the line number. This can allow you to stop at certain lines before the run and check variables
39+
40+
* Network
41+
42+
The network tab shows all information transmitted to/from your computer to the server (website).
43+
44+
![](./images/network2.png)
45+
46+
![](./images/network_3.png)
47+
48+
* Sources
49+
50+
The sources tab shows a listing of all files on the server that were requested.
51+
52+
![](./images/sources.png)
53+
54+
* Application
55+
56+
The application tab shows the saved cookies, local storage, and other information stored in your browser.
57+
58+
![](./images/application.png)
59+
60+
This is not an exhaustive list, but just a few useful tabs within Devtools.
61+
62+
## Encodings you should know about:
63+
64+
base64 - Looks like this
65+
![](./images/base64.png)
66+
67+
url encoding - Looks like this
68+
69+
![](./images/url_encode.png)
70+
71+
You can use [CyberChef](https://gchq.github.io/CyberChef/) to decode.
72+
73+
## SQL Injections
74+
75+
More in-depth explanations can be found in the Web 2 slides about SQL.
76+
77+
SQL, or Structured Query Language is a language for fetching information from a server.
78+
79+
For example,
80+
81+
```sql
82+
SELECT netid, firstname FROM students WHERE lastname = "Tables"
83+
```
84+
85+
![Alt text](./images/sql.png)
86+
87+
If code is written incorrectly, you can modify an SQL Statement as shown above.
88+
89+
More details on SQL: https://portswigger.net/web-security/sql-injection
90+
Resource on SQL Union Attack: https://portswigger.net/web-security/sql-injection/union-attacks
91+
92+
## Command Injections
93+
94+
Command Injection lets you execute multiple linux commands at the same time. It is very similar to SQL Injection, except instead of
95+
changing a database query, you are changing commands executed in the command line.
96+
97+
For example, in your terminal, you are able to execute multiple commands using the `;` ability
98+
99+
```
100+
$> echo "command 1"; echo "command 2"
101+
command 1
102+
command 2
103+
```
104+
105+
If you are able to "inject" something directly into the command you are executing, you can make it do additional things.
106+
107+
```
108+
$> echo "YOUR INPUT"
109+
```
110+
111+
If I had set `YOUR INPUT` to `-HI"; ls ; "BYE-`
112+
113+
then the command would look like
114+
115+
```
116+
echo "-HI"; ls; "BYE-"
117+
```
118+
119+
Some useful commands are:
120+
121+
+ `ls` - list files
122+
+ `cat x.txt` - output the contents of the file `x.txt`
123+
124+
If you want more resources on learning the linux command line...
125+
126+
+ Review our [Setup/Terminal Meeting Slides](https://sigpwny.com/meetings/fa2023/2023-09-03/)
127+
128+
## Cross Site Scripting (XSS)
129+

0 commit comments

Comments
 (0)