Write up 2013-MISC-75 CTF - QuânSysAd's Blog

02 tháng 8 2018

Write up 2013-MISC-75 CTF



Tạo chương trình tính tổng số nguyên bằng C
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int CheckSoNguyenTo(int n);

int main (int argc, char  * argv[] ) {
    printf("Program Name: %s\n", argv[0] );
    if(argc > 1) {
        int TongSoNguyenTo = 0;
        int i;
        long SoLuongSoNguyenTo;
        char * p;
        SoLuongSoNguyenTo = strtol (argv[1], &p, 10);
            int Counter = 0;
            int j;
            for (j = 0 ; ; j++ ) {
                if ( CheckSoNguyenTo(j) == 1 ) {
                    TongSoNguyenTo += j;
                    Counter++;
                }
                if ( Counter == SoLuongSoNguyenTo ) break;
            }

        printf("%d\n", TongSoNguyenTo );
      }
    return 0;
}

int CheckSoNguyenTo(int n) {
    if(n==0||n==1) return 0;
    int i;
    for(i=2; i<=(int)sqrt(n) ;i++ )
        if( n%i == 0 )
        return 0;
    return 1;
}
Tiếp theo dùng curl để lấy kết quả
for KetQua in $(Count=$(curl -s 'http://hack.bckdr.in/2013-MISC-75/misc75.php' -H 'Connection: keep-alive' -H 'Pragma: no-cache' -H 'Cache-Control: no-cache' -H 'Upgrade-Insecure-Requests: 1' -H 'User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: en,en-US;q=0.9' -H 'Cookie: PHPSESSID=tuna91q6r9frkoqah08esoerl5' --compressed | grep Find | awk '{print $16}') && \
./tsotest1 $Count)
do
curl -s 'http://hack.bckdr.in/2013-MISC-75/misc75.php' -H 'Connection: keep-alive' -H 'Pragma: no-cache' -H 'Cache-Control: no-cache' -H 'Origin: http://hack.bckdr.in' -H 'Upgrade-Insecure-Requests: 1' -H 'Content-Type: application/x-www-form-urlencoded' -H 'User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8' -H 'Referer: http://hack.bckdr.in/2013-MISC-75/misc75.php' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: en,en-US;q=0.9' -H 'Cookie: PHPSESSID=tuna91q6r9frkoqah08esoerl5' --data "answer=${KetQua}" --compressed
done
Kết quả:
 Nope ! The sum of primes you just submitted is wrong!
 Nope ! The sum of primes you just submitted is wrong!
 Nope ! The sum of primes you just submitted is wrong!
Congratulations! You passed it . Your award ==> 2ac4a6e921c6a5f5f36e8300896b597f9b4f83dc197294ca39fc3a862c734856
Ta có kết quả: 2ac4a6e921c6a5f5f36e8300896b597f9b4f83dc197294ca39fc3a862c734856

Không có nhận xét nào: