Protostar net0

发布时间:2020-08-01 14:43:06 作者:terrying
来源:网络 阅读:433

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();
}

在这关其实是考验写代码的能力。题目的意思是在机器上运行了这个程序,需要远程与这个程序打交道,从而达到题目的要求。
从题目得知会自动生成一个随机数返回给客户端,要求客户将这串数字以小端unsigned int型返回来即可。这里是用Python实现的。
#!/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)
        

运行结果:
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




推荐阅读:
  1. 如何在pycharm 中对Structure界面进行设置
  2. 使用Vant+postcss-pxtorem 怎么实现一个浏览器适配功能

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

protostar net0 tos st

上一篇:php中mysql出现500错误的解决方法

下一篇:虚拟主机中php修改参数的方法

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》