Skip to content

Commit 9a8d90f

Browse files
committed
Quartz sync: Oct 1, 2024, 9:57 PM
1 parent a054034 commit 9a8d90f

9 files changed

Lines changed: 89 additions & 86 deletions

File tree

169 KB
Loading
246 KB
Loading
102 KB
Loading
36.4 KB
Loading

content/Knowledge/Base64.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
modified: 2024-09-25T22:27:30+08:00
2+
modified: 2024-10-01T20:51:41+08:00
33
---
44
### Introduction
55
**Base64 encoding** is a format designed to prevent communication “mishaps” during the transfer of binary information. It achieves this through the conversion of binary data and a “lookup table” — data is eventually made in a stream of _ASCII_ characters, which can then be transmitted and decoded. On base 64 encoded data, the resultant string is always larger than the original (i.e. this is _not_ a compression algorithm). Another important distinction is that base 64 _does not_ encrypt any information — it uses a “standard” table of characters to encode and decode information. In other words, any base-64 string can be decoded, as long as the string was encoded using a standard set of characters (which the decoder can also understand). (_What Is Base64 Encoding & Decoding?_, n.d.)

content/PicoCTF/Cryptography/interencdec.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Creation Date:
88
Last Date:
99
References:
1010
draft:
11-
modified: 2024-09-25T22:28:02+08:00
11+
modified: 2024-10-01T20:51:41+08:00
1212
---
1313
## Challenge Description
1414

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
---
2+
tags:
3+
- Forensics
4+
- medium
5+
- tar
6+
- Python
7+
Creation Date:
8+
Last Date:
9+
References:
10+
draft:
11+
modified: 2024-10-01T21:57:27+08:00
12+
---
13+
## Challenge Description
14+
15+
![[PicoCTF like1000.png]]
16+
17+
The challenge description implies that we will probably have to extract the contents of the provided `tar` file repeatedly until we finally find a flag. Let's explore.
18+
19+
### Understanding the challenge
20+
![[PicoCTF like1000 2.png]]
21+
22+
We first download the provided `tar` file by running `wget <link>`. The downloaded file is named `1000.tar`. To extract tar files, I usually run the following command:
23+
24+
```bash
25+
tar -xvf < file-name >
26+
```
27+
28+
- `-x` : Extracts files from a tar archive
29+
- `-v` : Verbosely list files processed
30+
- `-f` : Specifies archive file
31+
32+
After running `tar -xvf 1000.tar`, we can see that 2 files have been created (`999.tar` and `filler.txt`).
33+
34+
I thought that `filler.txt` may contain something useful or suspicious, but this was the contents in this file:
35+
36+
```
37+
alkfdslkjf;lkjfdsa;lkjfdsa
38+
```
39+
40+
It seems like there is nothing of interest currently. I proceeded to run the same command on `999.tar`, and received a similar output, in this case `998.tar`. I tried to `cat` the contents of `filler.txt` again, and the same gibberish was displayed.
41+
42+
However, since another `tar` file was created this time as well, it seemed like the solution to this challenge is to continue extracting the files again and again, one after the other.
43+
44+
>[!faq] PicoCTF Hint: Try and script this, it'll save you a lot of time
45+
46+
### Attempting to solve
47+
To do this, I made the following Python script:
48+
49+
>[!abstract] Python script
50+
>
51+
>```python
52+
>import tarfile
53+
>
54+
>def is_safe_tar(member, path):
55+
> return member
56+
>
57+
>for i in range(998, 0, -1):
58+
> # Extract file
59+
> with tarfile.open(f'{i}.tar', 'r') as tar:
60+
> tar.extractall(path='.', filter=is_safe_tar)
61+
>```
62+
>
63+
>>[!faq] Note
64+
>>
65+
>>The reason why is_safe_tar function was required is because there will be an error message displayed if a filter is not specified. This is aimed at preventing unsafe files from being extracted.
66+
67+
68+
69+
![[PicoCTF like1000 3.png]]
70+
71+
Running the script recursively extracts the existing `tar` files in the directory we are in. Running `ls` after successful execution of the script reveals that a file named `flag.png` created in this directory.
72+
73+
![[PicoCTF like1000 4.png]]
74+
75+
Opening this image file awards us with the flag for this challenge.
76+
77+
78+
> [!NOTE] Flag
79+
>picoCTF{l0t5_0f_TAR5}

content/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: CTF Writeups
3-
modified: 2024-09-21T22:11:13+08:00
3+
modified: 2024-10-01T20:51:41+08:00
44
---
55

66
![[banner.jpg]]

try.py

Lines changed: 7 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,9 @@
1-
from random import randint
2-
import sys
3-
4-
5-
def generator(g, x, p):
6-
return pow(g, x) % p
7-
8-
9-
def encrypt(plaintext, key):
10-
cipher = []
11-
for char in plaintext:
12-
cipher.append(((ord(char) * key*311)))
13-
return cipher
14-
15-
16-
def is_prime(p):
17-
v = 0
18-
for i in range(2, p + 1):
19-
if p % i == 0:
20-
v = v + 1
21-
if v > 1:
22-
return False
23-
else:
24-
return True
25-
26-
27-
def dynamic_xor_encrypt(plaintext, text_key):
28-
cipher_text = ""
29-
key_length = len(text_key)
30-
for i, char in enumerate(plaintext[::-1]):
31-
key_char = text_key[i % key_length]
32-
encrypted_char = chr(ord(char) ^ ord(key_char))
33-
cipher_text += encrypted_char
34-
return cipher_text
35-
36-
37-
def test(plain_text, text_key):
38-
p = 97
39-
g = 31
40-
if not is_prime(p) and not is_prime(g):
41-
print("Enter prime numbers")
42-
return
43-
a = randint(p-10, p)
44-
b = randint(g-10, g)
45-
print(f"a = {a}")
46-
print(f"b = {b}")
47-
u = generator(g, a, p)
48-
v = generator(g, b, p)
49-
key = generator(v, a, p)
50-
b_key = generator(u, b, p)
51-
shared_key = None
52-
if key == b_key:
53-
shared_key = key
54-
else:
55-
print("Invalid key")
56-
return
57-
semi_cipher = dynamic_xor_encrypt(plain_text, text_key)
58-
cipher = encrypt(semi_cipher, shared_key)
59-
print(f'cipher is: {cipher}')
60-
61-
62-
def decrypt(cipher, key):
63-
plain_text = ""
64-
for char in cipher:
65-
plain_text += chr(char // key // 311)
66-
return plain_text
67-
68-
69-
def dynamic_xor_decrypt(cipher_text, text_key):
70-
return dynamic_xor_encrypt(cipher_text, text_key)
71-
72-
73-
def test_decrypt(cipher, key, text_key):
74-
semi_cipher = decrypt(cipher, key)
75-
plain_text = dynamic_xor_decrypt(semi_cipher, text_key)
76-
print(f"plain text is: {plain_text}")
77-
78-
79-
if __name__ == "__main__":
80-
message = sys.argv[1]
81-
test(message, "trudeau")
82-
83-
# number of ciphers is dependent on the length of the message.
1+
import tarfile
842

3+
def is_safe_tar(member, path):
4+
return member
855

6+
for i in range(998, 0, -1):
7+
# Decompress the file
8+
with tarfile.open(f'{i}.tar', 'r') as tar:
9+
tar.extractall(path='.', filter=is_safe_tar)

0 commit comments

Comments
 (0)