Skip to content

Commit 9c3c92d

Browse files
JorianWoltjergitbook-bot
authored andcommitted
GitBook: [#53] Add highlights to shell commands
1 parent b499c35 commit 9c3c92d

26 files changed

+269
-348
lines changed

SUMMARY.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555

5656
## 🐧 Linux
5757

58-
* [Shells](linux/shells.md)
58+
* [Shells](linux/hacking-linux-boxes.md)
5959
* [Linux Privilege Escalation](linux/linux-privilege-escalation/README.md)
6060
* [Enumeration](linux/linux-privilege-escalation/enumeration.md)
6161
* [Sudo](linux/linux-privilege-escalation/sudo.md)
@@ -70,7 +70,7 @@
7070
## ❔ Other
7171

7272
* [WSL Guide](other/wsl-guide.md)
73-
* [OSINT](other/osint.md)
73+
* [OSINT](other/osint/README.md)
7474

7575
## 🔨 TODO
7676

@@ -105,6 +105,6 @@
105105
* [Python](todo/python.md)
106106
* [Hacking Windows Boxes](todo/hacking-windows-boxes.md)
107107
* [Windows Privilege Escalation](todo/windows-privilege-escalation.md)
108-
* [Networking](todo/networking.md)
109-
* [Googling](todo/googling.md)
110-
* [WaybackMachine](todo/waybackmachine.md)
108+
* [Networking](linux/networking.md)
109+
* [Googling](other/osint/todo-googling.md)
110+
* [WaybackMachine](other/osint/todo-waybackmachine.md)

cryptography/hashing/README.md

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,19 @@ To create such a file you can use the [poc\_no.sh](https://github.com/cr-marcste
6969
In the example above I used a file containing `"A"*64 + "B"*64 + "C"*64 + "test"` as the prefix. This will make sure the identical prefix starts with AAA...CCC and the collision blocks start with "test". \
7070
Then after this, I added `"D"*64 + "E"*64 + "F"*64` to the generated collisions because any data after will only change the hash, but the collision will remain. 
7171

72-
```shell-session
73-
$ python3 -c 'print("A"*64 + "B"*64 + "C"*64 + "test", end="")' > prefix # Create prefix
74-
$ ../scripts/poc_no.sh prefix # Do collision (takes a few minutes)
75-
...
76-
$ md5sum collision*.bin # MD5 sums are the same
77-
a83232a6730cdd6102d002e31ffd1c3f collision1.bin
72+
<pre class="language-shell-session"><code class="lang-shell-session"><strong>$ python3 -c 'print("A"*64 + "B"*64 + "C"*64 + "test", end="")' > prefix # Create prefix
73+
</strong><strong>$ ../scripts/poc_no.sh prefix # Do collision (takes a few minutes)
74+
</strong>...
75+
<strong>$ md5sum collision*.bin # MD5 sums are the same
76+
</strong>a83232a6730cdd6102d002e31ffd1c3f collision1.bin
7877
a83232a6730cdd6102d002e31ffd1c3f collision2.bin
79-
$ # Append data to collisions
80-
$ cat collision1.bin <(python3 -c 'print("D"*64 + "E"*64 + "F"*64, end="")') > collision1_extra.bin
81-
$ cat collision2.bin <(python3 -c 'print("D"*64 + "E"*64 + "F"*64, end="")') > collision2_extra.bin
82-
$ md5sum collision*_extra.bin # MD5 sums still match
83-
e8842904b573ed3cd545a5b116f70af8 collision1_extra.bin
78+
# # Append data to collisions
79+
<strong>$ cat collision1.bin &#x3C;(python3 -c 'print("D"*64 + "E"*64 + "F"*64, end="")') > collision1_extra.bin
80+
</strong><strong>$ cat collision2.bin &#x3C;(python3 -c 'print("D"*64 + "E"*64 + "F"*64, end="")') > collision2_extra.bin
81+
</strong><strong>$ md5sum collision*_extra.bin # MD5 sums still match
82+
</strong>e8842904b573ed3cd545a5b116f70af8 collision1_extra.bin
8483
e8842904b573ed3cd545a5b116f70af8 collision2_extra.bin
85-
```
84+
</code></pre>
8685

8786
### MD5 - Chosen Prefix
8887

@@ -95,7 +94,7 @@ To create a collision like this, you could use the [cpc.sh](https://github.com/c
9594
I've let a VPS with 24 cores run for 1.5 days to find a chosen-prefix collision like this. I chose one prefix of a simple 256x256 png image, and the other prefix to be an XSS and PHP shell payload. So I could leave the terminal and look back at it later I used the `screen` command to start a session, and used `screen -r` every once in a while to check back into it. Another way would be to redirect the output to some log file to check.&#x20;
9695

9796
```shell-session
98-
$ # From hashclash clone (and build)
97+
# # From hashclash clone (and build)
9998
$ mkdir workdir && cd workdir
10099
$ ../scripts/cpc.sh 256.png prefix.php # Takes a long time
101100
```
@@ -169,15 +168,14 @@ In HTML, this can be done by looking at the `innerHTML` with `charCodeAt(102)` i
169168
1. [https://arw.me/f/1.html](https://arw.me/f/1.html)
170169
2. [https://arw.me/f/2.html](https://arw.me/f/2.html)
171170
172-
```shell-session
173-
$ wget https://arw.me/f/1.html && wget https://arw.me/f/2.html
174-
$ sha1sum 1.html 2.html # SHA1 collision
175-
ba97502d759d58f91ed212d7c981e0cfdfb70eef 1.html
171+
<pre class="language-shell-session"><code class="lang-shell-session"><strong>$ wget https://arw.me/f/1.html &#x26;&#x26; wget https://arw.me/f/2.html
172+
</strong><strong>$ sha1sum 1.html 2.html # SHA1 collision
173+
</strong>ba97502d759d58f91ed212d7c981e0cfdfb70eef 1.html
176174
ba97502d759d58f91ed212d7c981e0cfdfb70eef 2.html
177-
$ sha256sum 1.html 2.html # SHA256 does not
178-
4477a514fa5e948d69e064a4e00378c69262e32e36c079b76226ae50e3d312cf 1.html
175+
<strong>$ sha256sum 1.html 2.html # SHA256 does not
176+
</strong>4477a514fa5e948d69e064a4e00378c69262e32e36c079b76226ae50e3d312cf 1.html
179177
71c484897c7af6cb34cffa8f7c12dc3bf7fc834ed7f57123e21258d2f3fc4ba6 2.html
180-
```
178+
</code></pre>
181179
182180
## Length-extension Attack
183181

cryptography/hashing/cracking-hashes.md

Lines changed: 34 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -49,24 +49,22 @@ Hashcat: $pkzip$1*2*2*0*11*5*22dc8822*0*42*0*11*55ee*bfcbf39396ab
4949

5050
Sometimes you also need to **extract** a hash from a password-protected ZIP file for example. This is where John has a lot of useful tools. In the [`john/run`](https://github.com/openwall/john/tree/bleeding-jumbo/run) directory of your John the Ripper installation, there should be a lot of scripts and programs that allow you to convert certain files to the john format. For `.zip` archives there is the `zip2john` utility:
5151

52-
```shell-session
53-
$ zip2john test.zip
54-
ver 1.0 efh 5455 efh 7875 test.zip/flag.txt PKZIP Encr: 2b chk, TS_chk, cmplen=17, decmplen=5, crc=22DC8822 ts=55EE cs=55ee type=0
55-
test.zip/flag.txt:$pkzip$1*2*2*0*11*5*22dc8822*0*42*0*11*55ee*bfcbf39396ab87b78eb574a02dd5020f23*$/pkzip$:flag.txt:test.zip::test.zip
56-
$ zip2john test.zip > john.hash
57-
$ cat john.hash
52+
<pre class="language-shell-session"><code class="lang-shell-session"><strong>$ zip2john test.zip
53+
</strong>ver 1.0 efh 5455 efh 7875 test.zip/flag.txt PKZIP Encr: 2b chk, TS_chk, cmplen=17, decmplen=5, crc=22DC8822 ts=55EE cs=55ee type=0
5854
test.zip/flag.txt:$pkzip$1*2*2*0*11*5*22dc8822*0*42*0*11*55ee*bfcbf39396ab87b78eb574a02dd5020f23*$/pkzip$:flag.txt:test.zip::test.zip
59-
```
55+
<strong>$ zip2john test.zip > john.hash
56+
</strong><strong>$ cat john.hash
57+
</strong>test.zip/flag.txt:$pkzip$1*2*2*0*11*5*22dc8822*0*42*0*11*55ee*bfcbf39396ab87b78eb574a02dd5020f23*$/pkzip$:flag.txt:test.zip::test.zip
58+
</code></pre>
6059

6160
There are a lot of files that can be converted to john like this, just find one for the file format you need and convert it using the script.&#x20;
6261

6362
You can also use John to convert the hashes from a file, and then actually crack them with **Hashcat**. As stated above hashcat has a slightly different hash format, but from what I've found it's almost always just splitting the john hash by `:` colons and then taking the second part. That way you're only getting the hash without any other information.&#x20;
6463

65-
```shell-session
66-
$ cat john.hash | awk -F: '{print $2}' > hashcat.hash
67-
$ cat hashcat.hash
68-
$pkzip$1*2*2*0*11*5*22dc8822*0*42*0*11*55ee*bfcbf39396ab87b78eb574a02dd5020f23*$/pkzip$
69-
```
64+
<pre class="language-shell-session"><code class="lang-shell-session"><strong>$ cat john.hash | awk -F: '{print $2}' > hashcat.hash
65+
</strong><strong>$ cat hashcat.hash
66+
</strong>$pkzip$1*2*2*0*11*5*22dc8822*0*42*0*11*55ee*bfcbf39396ab87b78eb574a02dd5020f23*$/pkzip$
67+
</code></pre>
7068

7169
## [Hashcat](https://hashcat.net/hashcat/)
7270

@@ -120,8 +118,9 @@ password?d => password0 - password9 # Can put text in mask
120118
```
121119
{% endcode %}
122120

123-
<pre class="language-shell-session"><code class="lang-shell-session"><strong>$ hashcat -m 0 hash.txt -a 3 -1 ?l?u ?1?l?l?l?l?l19?d?d
124-
</strong></code></pre>
121+
```shell-session
122+
$ hashcat -m 0 hash.txt -a 3 -1 ?l?u ?1?l?l?l?l?l19?d?d
123+
```
125124

126125
#### Cracking IP addresses
127126

@@ -147,16 +146,15 @@ ROOT123
147146

148147
Using actual `.rule` files with the `-r` argument you can even specify multiple rules to create lots of passwords quickly:
149148

150-
```shell-session
151-
$ cat case.rule
152-
l
149+
<pre class="language-shell-session"><code class="lang-shell-session"><strong>$ cat case.rule
150+
</strong>l
153151
u
154-
$ cat 123.rule
155-
$1
152+
<strong>$ cat 123.rule
153+
</strong>$1
156154
$2
157155
$3
158-
$ hashcat --stdout -r case.rule -r 123.rule list.txt
159-
password1
156+
<strong>$ hashcat --stdout -r case.rule -r 123.rule list.txt
157+
</strong>password1
160158
PASSWORD1
161159
password2
162160
PASSWORD2
@@ -174,7 +172,7 @@ root2
174172
ROOT2
175173
root3
176174
ROOT3
177-
```
175+
</code></pre>
178176

179177
## [John the Ripper](https://github.com/openwall/john)
180178

@@ -188,19 +186,16 @@ A list of example hashes with their name and john mode
188186

189187
John is pretty specific with its arguments. For a custom wordlist, make sure to use `-wordlist=` with the `=` sign. If you do not include the `=` sign it will give a weird "invalid UTF-8" error. Here is an example of how you should run john:
190188

191-
{% code title="Cracking an MD5 hash" %}
192-
```shell-session
193-
$ cat hash.txt
194-
5ebe2294ecd0e0f08eab7690d2a6ee69
195-
$ john --wordlist=/list/rockyou.txt --format=raw-md5 hash.txt
196-
Loaded 1 password hash (Raw-MD5 [MD5 256/256 AVX2 8x3])
189+
<pre class="language-shell-session" data-title="Cracking an MD5 hash"><code class="lang-shell-session"><strong>$ cat hash.txt
190+
</strong>5ebe2294ecd0e0f08eab7690d2a6ee69
191+
<strong>$ john --wordlist=/list/rockyou.txt --format=raw-md5 hash.txt
192+
</strong>Loaded 1 password hash (Raw-MD5 [MD5 256/256 AVX2 8x3])
197193
Press 'q' or Ctrl-C to abort, 'h' for help, almost any other key for status
198194
secret (?)
199195
1g 0:00:00:00 DONE (2022-08-18 22:05) 50.00g/s 19200p/s 19200c/s 19200C/s 123456..michael1
200196
Use the "--show --format=Raw-MD5" options to display all of the cracked passwords reliably
201197
Session completed.
202-
```
203-
{% endcode %}
198+
</code></pre>
204199

205200
### Cracking shadow hashes
206201

@@ -242,25 +237,23 @@ $ make install
242237

243238
Then after it's installed, you can use the `hcxpcapngtool` command to extract the handshakes from the capture. Then use hashcat with mode 22000 or 22001 to crack the password:
244239

245-
```shell-session
246-
$ hcxpcapngtool capture.pcap -o capture.hashes
247-
$ cat capture.hashes
248-
WPA*02*a462a7029ad5ba30b6af0df391988e45*000c4182b255*000d9382363a*436f6865726572*3e8e967dacd960324cac5b6aa721235bf57b949771c867989f49d04ed47c6933*0203007502010a00100000000000000000cdf405ceb9d889ef3dec42609828fae546b7add7baecbb1a394eac5214b1d386000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001630140100000fac020100000fac040100000fac020000*02
249-
$ hashcat -m 22000 hash.txt list.txt
250-
...
240+
<pre class="language-shell-session"><code class="lang-shell-session"><strong>$ hcxpcapngtool capture.pcap -o capture.hashes
241+
</strong><strong>$ cat capture.hashes
242+
</strong>WPA*02*a462a7029ad5ba30b6af0df391988e45*000c4182b255*000d9382363a*436f6865726572*3e8e967dacd960324cac5b6aa721235bf57b949771c867989f49d04ed47c6933*0203007502010a00100000000000000000cdf405ceb9d889ef3dec42609828fae546b7add7baecbb1a394eac5214b1d386000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001630140100000fac020100000fac040100000fac020000*02
243+
<strong>$ hashcat -m 22000 hash.txt list.txt
244+
</strong>...
251245
a462a7029ad5ba30b6af0df391988e45:000c4182b255:000d9382363a:Coherer:Induction
252-
```
246+
</code></pre>
253247

254248
After you find the password, you can use Wireshark to decrypt the packets (see [#decrypting](../../forensics/wireshark.md#decrypting "mention"))
255249

256250
### WEP
257251

258252
WEP is an old Wifi encryption standard where every device uses the same key. It also happens to be easily crackable with enough traffic. It requires lots of IVs (Initialization Vectors), which can come from lots of normal traffic, or you can manually send specific packets that would trigger IVs to be generated if you have access to the network (see [this tutorial](https://www.aircrack-ng.org/doku.php?id=simple\_wep\_crack)). When you have a packet capture with enough information, you can use [`aircrack-ng`](https://www.aircrack-ng.org/) to quickly find the key:
259253

260-
```shell-session
261-
$ aircrack-ng capture.cap
262-
...
254+
<pre class="language-shell-session"><code class="lang-shell-session"><strong>$ aircrack-ng capture.cap
255+
</strong>...
263256
KEY FOUND! [ 1F:1F:1F:1F:1F ]
264-
```
257+
</code></pre>
265258

266259
After it completes, you can use the key it found (hex format) to decrypt all the traffic (see [#decrypting](../../forensics/wireshark.md#decrypting "mention"))

cryptography/z3-solver.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ description: The Z3 Theorem Prover can automatically solve puzzles in Python
88

99
The Z3 Theorem Prover is a Python library that can automatically solve puzzles you give it in code.&#x20;
1010

11-
```shell
12-
pip install z3-solver
11+
```shell-session
12+
$ pip install z3-solver
1313
```
1414

1515
The idea is that you define Z3 variables and perform certain operations on them. Then you can add constraints to the solver and lets it fulfill those constraints. To learn using Z3 I highly suggest looking up some random puzzles and trying to solve them with Z3. There are lots of useful functions in Z3 to try out.&#x20;

forensics/archives.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,14 @@ Doing it manually would require you to first get a hash using a tool like `zip2j
2424

2525
An interesting little thing about most archive file formats is the fact that when they are encrypted, you can still read the filenames and structure, only the content is encrypted. This can already give a good idea of what kind of files the archive contains.&#x20;
2626

27-
```shell-session
28-
$ unzip -v archive.zip
29-
Archive: archive.zip
27+
<pre class="language-shell-session"><code class="lang-shell-session"><strong>$ unzip -v archive.zip
28+
</strong>Archive: archive.zip
3029
Length Method Size Cmpr Date Time CRC-32 Name
3130
-------- ------ ------- ---- ---------- ----- -------- ----
3231
15 Stored 15 0% 1970-01-01 00:00 21c0cb62 file.txt
3332
-------- ------- --- -------
3433
15 15 0% 1 file
35-
```
34+
</code></pre>
3635

3736
As you can see, even the size and a CRC32 are present. This CRC is a checksum of the **unencrypted** file content, so if you can guess the content you can confirm it by taking the CRC. This allows for brute-forcing content of very small files as well. See this tool for an implementation of that:
3837

forensics/file-formats.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ A big collection of drawings of file formats to understand them quickly
1919
Sometimes when data tries to be hidden inside another file, it is just pasted right into the host file. Meaning that the bytes of the secret file are just somewhere in the other file. Using [binwalk](https://github.com/ReFirmLabs/binwalk) you can check for known file signatures in a file to see if it embeds something. \
2020
Using the following command you can also recursively extract all of these into a `.extracted` folder:
2121

22-
```shell-session
23-
$ binwalk -eM file.bin
24-
DECIMAL HEXADECIMAL DESCRIPTION
22+
<pre class="language-shell-session"><code class="lang-shell-session"><strong>$ binwalk -eM file.bin
23+
</strong>DECIMAL HEXADECIMAL DESCRIPTION
2524
--------------------------------------------------------------------------------
2625
0 0x0 TRX firmware header, little endian, image size: 37883904 bytes, CRC32: 0x95C5DF32, flags: 0x1, version: 1, header size: 28 bytes, loader offset: 0x1C, linux kernel offset: 0x0, rootfs offset: 0x0
2726
28 0x1C uImage header, header size: 64 bytes, header CRC: 0x780C2742, created: 2018-10-10 02:12:20, image size: 2150281 bytes, Data Address: 0x8000, Entry Point: 0x8000, data CRC: 0xA097CFEA, OS: Linux, CPU: ARM, image type: OS Kernel Image, compression type: none, image name: "DD-WRT"
@@ -32,8 +31,8 @@ DECIMAL HEXADECIMAL DESCRIPTION
3231
2117484 0x204F6C device tree image (dtb)
3332
3145756 0x30001C UBI erase count header, version: 1, EC: 0x0, VID header offset: 0x800, data offset: 0x1000
3433

35-
$ binwalk --dd='.*' file.bin # Another way to extract all file signatures
36-
```
34+
<strong>$ binwalk --dd='.*' file.bin # Another way to extract all file signatures
35+
</strong></code></pre>
3736

3837
{% hint style="warning" %}
3938
A common false positive with PNGs is `Zlib compressed data`. This is because PNG uses Zlib for compression in its own file format, so it is recognized by binwalk. But very often this compressed data just covers the entire file
@@ -55,9 +54,8 @@ Image files like PNG can have a lot of hidden info. It's a relatively complex fi
5554

5655
A quick check you can do to see if it is a completely valid PNG file is using [pngcheck](http://www.libpng.org/pub/png/apps/pngcheck.html):
5756

58-
```shell-session
59-
$ pngcheck -h
60-
Test PNG, JNG or MNG image files for corruption, and print size/type info.
57+
<pre class="language-shell-session"><code class="lang-shell-session"><strong>$ pngcheck -h
58+
</strong>Test PNG, JNG or MNG image files for corruption, and print size/type info.
6159

6260
Usage: pngcheck [-7cfpqtv] file.{png|jng|mng} [file2.{png|jng|mng} [...]]
6361
or: ... | pngcheck [-7cfpqstvx]
@@ -74,9 +72,9 @@ Options:
7472
-v test verbosely (print most chunk data)
7573
-x search for PNGs within another file and extract them when found
7674

77-
$ pngcheck image.png
78-
OK: image.png (1920x1080, 32-bit RGB+alpha, non-interlaced, 96.6%).
79-
```
75+
<strong>$ pngcheck image.png
76+
</strong>OK: image.png (1920x1080, 32-bit RGB+alpha, non-interlaced, 96.6%).
77+
</code></pre>
8078

8179
PNG files consist of **chunks** of bytes that tell something about the image. The most common one is `IDAT` which contains the pixel data of the image. An image always ends with `IEND` and 4 checksum bytes (every chunk has the checksum).&#x20;
8280

forensics/file-recovery.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ description: Recovering content of deleted files
66

77
Find disks using `mount` and looking for `sd[a-z]`:
88

9-
```shell-session
10-
$ mount
11-
/dev/sdb on / type ext4 (rw,relatime,discard,errors=remount-ro,data=ordered)
9+
<pre class="language-shell-session"><code class="lang-shell-session"><strong>$ mount
10+
</strong>/dev/sdb on / type ext4 (rw,relatime,discard,errors=remount-ro,data=ordered)
1211
...
13-
```
12+
</code></pre>
1413

1514
Then grep for any known text:
1615

forensics/grep.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,9 @@ $ grep [OPTIONS...] PATTERNS [FILES...]
1616
* `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
1717
* `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
1818

19-
{% code title="Simple example" %}
20-
```shell-session
21-
$ grep something file.txt
22-
And here is something.
23-
```
24-
{% endcode %}
19+
<pre class="language-shell-session" data-title="Simple example"><code class="lang-shell-session"><strong>$ grep something file.txt
20+
</strong>And here is something.
21+
</code></pre>
2522

2623
{% hint style="info" %}
2724
See all documentation about the options with `man grep`

0 commit comments

Comments
 (0)