溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Protostar net0

發(fā)布時(shí)間:2020-08-01 14:43:06 來源:網(wǎng)絡(luò) 閱讀:448 作者:terrying 欄目:安全技術(shù)

About

This level takes a look at converting strings to little endian integers.
This level is at /opt/protostar/bin/net0

Source code

#include "../common/common.c"

#define NAME "net0"
#define UID 999
#define GID 999
#define PORT 2999

void run()
{
unsigned int i;
unsigned int wanted;

wanted = random();

printf("Please send '%d' as a little endian 32bit int\n", wanted);

if(fread(&i, sizeof(i), 1, stdin) == NULL) {
    errx(1, ":(\n");
}

if(i == wanted) {
    printf("Thank you sir/madam\n");
} else {
    printf("I'm sorry, you sent %d instead\n", i);
}
}

int main(int argc, char **argv, char **envp)
{
int fd;
char *username;

/* Run the process as a daemon */
background_process(NAME, UID, GID);

/* Wait for socket activity and return */
fd = serve_forever(PORT);

/* Set the client socket to STDIN, STDOUT, and STDERR */
set_io(fd);

/* Don't do this :> */
srandom(time(NULL));

run();
}

在這關(guān)其實(shí)是考驗(yàn)寫代碼的能力。題目的意思是在機(jī)器上運(yùn)行了這個(gè)程序,需要遠(yuǎn)程與這個(gè)程序打交道,從而達(dá)到題目的要求。
從題目得知會(huì)自動(dòng)生成一個(gè)隨機(jī)數(shù)返回給客戶端,要求客戶將這串?dāng)?shù)字以小端unsigned int型返回來即可。這里是用Python實(shí)現(xiàn)的。
#!/usr/bin/env python

from socket import *
from struct import *
from optparse import OptionParser

def main(hostname,port):
        s = socket(AF_INET,SOCK_STREAM)
        s.connect((hostname,port))
        
        rec = s.recv(1024)
        print rec
        index1 = rec.find("'")+1
        index2 = rec.rfind("'")
        print rec[index1:index2]
        num = int(rec[index1:index2])
        s.send(pack("<I",num))
        rec = s.recv(1024)
        print rec

if __name__=="__main__":
        parse = OptionParser("usage: %prog [options]")
        parse.add_option("-H",dest="hostname",default="127.0.0.1",type="string",help="The ip of the target")
        parse.add_option("-P",dest="port",default=2999,type="int",help="The port of the host")
        
        (options,args)=parse.parse_args()
        
        main(options.hostname,options.port)
        

運(yùn)行結(jié)果:
D:\Python27\a\protostar>debug.py -H 192.168.0.71
Please send '1200002487' as a little endian 32bit int

1200002487
Thank you sir/madam




向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI