3 SECCON offered a nice array of challenges and while I had a quick look at most, I mainly concentrated on a crypto/web and a pwn one. Unfortunately not being able to solve either I spent most of my time on "lazy" which consisted of two stages, the first of which I solved rather quickly, but then getting totally stuck on the second part. While some of the other challenges, especially the stego ones, looked interesting they didn't seem very accessible without having experience in their domain, offering very little hints at possible avenues to test.
10 lazy.chal.seccon.jp 33333
12 lazy was a binary challenge whose description only contained a server address. After connecting a simple menu was presented that offered options to login, access Public contents or disconnect. The public area contained part of the challenge source code related to the login:
14 #define BUFFER_LENGTH 32
15 #define PASSWORD "XXXXXXXXXX"
16 #define USERNAME "XXXXXXXX"
19 char username[BUFFER_LENGTH];
20 char password[BUFFER_LENGTH];
21 char input_username[BUFFER_LENGTH];
22 char input_password[BUFFER_LENGTH];
24 memset(username,0x0,BUFFER_LENGTH);
25 memset(password,0x0,BUFFER_LENGTH);
26 memset(input_username,0x0,BUFFER_LENGTH);
27 memset(input_password,0x0,BUFFER_LENGTH);
29 strcpy(username,USERNAME);
30 strcpy(password,PASSWORD);
32 printf("username : ");
33 input(input_username);
34 printf("Welcome, %s\n",input_username);
36 printf("password : ");
37 input(input_password);
40 if(strncmp(username,input_username,strlen(USERNAME)) != 0){
41 puts("Invalid username");
45 if(strncmp(password,input_password,strlen(PASSWORD)) != 0){
46 puts("Invalid password");
54 void input(char *buf){
58 recv = (int)read(STDIN_FILENO,&buf[i],1);
70 This code contained to problems: Input parsing was only terminated upon encountering a newline which allows for a buffer overflow and overwriting the login information stored on the stack, and the printf-statement after entering a username could be used to print data from the stack. After some experimentation I had found the necessary padding to print the username and password variables:
72 leak_password_payload = "A" * 29 + "%s"
73 leak_username_payload = "A" * 29 + "B" * 32 + "%s"
75 Using those the login menu option could be used to access a private content area in which the full binary and a libc file was stored; because files containing dots in their name could not be downloaded and code to prevent directory traversal was present as well.
76 The download prompt contained another printf-vulnerability, and exploring it further I found that some environment variables were stored on the stack, including pwd and the home-directory which was used to define which folder was presented for downloading. Thinking the flag might be stored in another folder I thought about overwriting those paths, but because "/q/private" was appended to it arbitrary path access would still not have been possible. I also considered overwriting the GOT-entry of a linked function to divert program flow and skip some checks in the code and download other files, but because the binary had RELRO enabled (which it took me way to long to remember to check after having worked on the challenge for a while already) this option was out as well. In the end I was unable to get the final step of downloading the flag in time. lazy_solve.py contains a solution up to the final part which automatically downloads the login source code, leaks the username and password and downloads the challenge binary.
81 * Time spent: ~3 hours
82 ZPKay was a crypto challenge consisting of a website that offered registered users to send custom currency to other users by use of generated QR codes. After registration each user was given 500 units of the currency, and 1 million was required to reveal the flag. Registering multiple accounts and pooling the currency was possible but would have taken too long; the intended path seemed to be to fake a QR code that allowed for withdrawal of high enough amounts from the admin account that sent the initial batch to each new user.
83 Generating a couple of QR codes revealed that they encoded the username, the amount to be transferred, a proof and an hash:
85 username=w0y&amount=2&proof=MP49LF+ZPCw7Erx0RtFvs9aGKy2eglOEsOmKykBf9acYMSAw2VAOJC++LtkU1VQJLjFgomQpjsTKOnFZEi7SbRSm9y4xCjABuFt915o/jZvc45hTajCjjNDHQZ6/v3vc6jQSEOUSJ3n1huxiOEuhNEYpE0OAsfatSu6ijNz8aidLUXjd6hkXMCAwR02qBLuxG/ZqqJ1YOpPdkclDPgOo7f69GgCN1JBuXBUwCjD99BQC0lBQkDDjsWNBW03uis8/40UkaVtorRTntM8OFDAgMDQMPxacCXL7q+9nxQmSKQBxiAaoa/QPEcLUKsei9KAkMAowEXGyGgNDmfmQi942WhTZkSonB0dK54yt5bQf78FUTyUxCjBxEwWHGKwCK/rGCMvjXGYD02hJewvHqZPG6bgUQGfWGjEK&hash=76bb1b5eb3cb773acdd2e1ce12b02d242ea280f211722e314b06530d55680e88
87 Interestingly neither the proof nor the hash seemed to depend on the amount as both stayed the same with every new QR code generated, and encoding payloads with different amounts without the use of the website yielded usable codes as well. Looking around the site the hash turned out to be a user identification, and because the transaction overview on the starting page showed the hashes of trading partners the correct one for the admin account was known.
89 function formatTime(timestamp){
90 let dt = new Date(timestamp * 1000);
91 let time = dt.getFullYear() + "/" + (dt.getMonth()+1) + "/" + dt.getDate() + " " + dt.getHours() + ":" + dt.getMinutes();
95 function getAccountData()
97 $.get( "/api/accountData", function( data ) {
98 $("#balance").text(data["balance"]);
99 $("#flag").text(data["flag"]);
100 let tBody = $("#trx").find('tbody');
102 for(i=0; i<data["trxList"].length; ++i){
105 td.text(formatTime(data["trxList"][i][1]));
110 .attr("data-toggle", "popover")
111 .attr("data-trigger", "hover")
112 .attr("data-content", "Address is " + data["trxList"][i][3])
113 .attr("data-placement", "top")
114 .text(data["trxList"][i][2]);
118 td.text(data["trxList"][i][5]);
122 $('[data-toggle="popover"]').each(function(i, obj) {
123 var popover_target = $(this).data("popover-target");
129 content: function(obj) {
130 return $(popover_target).html();
137 $(document).ready(function(){
143 sendData["amount"] = $("#amount").val();
144 sendData["password"] = $("#password").val();
148 data:JSON.stringify(sendData),
149 contentType: "application/json; charset=utf-8",
151 success : function(data) {
152 if(data["status"] == "ok"){
153 $("#qr").html( data["dom"] );
155 $("#qr").html( data["error"]);
163 fileData = $("#qrImg").prop("files")[0];
164 formData = new FormData();
165 formData.append('file', fileData);
172 success : function(data) {
173 if(data["status"] == "ok"){
174 Snackbar.show({text: data["dom"]});
176 Snackbar.show({text: data["error"]});
182 The javascript of the page showed that other than the amount and the user password (as well as the session cookie) no information was sent to the server in order to generate the QR codes, which meant that the proof was generated once and stored serverside or was reconstructed with each request; however I did not find out how to get to the admin proof. Other teams seem to have solved it by simply generating QR codes with negative amounts encoded which would lead to the sending account getting credits added instead of subtracted, but I'm not sure whether that was the intended solution because the challenge name seemed to hint at some kind of zero knowledge-protocol being involved.
187 * Time spent: ~1 hour
188 Sandstorm was a forensics challenge consisting of a grainy black-and-white-picture that contained some short text. Thinking the monochromatic pixels might encode a binary message I tried finding some relevant data using [zsteg](https://github.com/zed-0xff/zsteg) and stegsolve, but nothing interesting turned up. As it [turns out](https://github.com/10secTW/ctf-writeup/tree/master/2019/SECCON%20CTF%20quals/Sandstorm) I was on the wrong track and the image hid a QR code of the flag.