Protostar net2

发布时间:2020-08-02 14:05:29 作者:terrying
来源:网络 阅读:325

This level is at /opt/protostar/bin/net2<h3 Droid Sans', sans-serif; font-weight: normal; line-height: 40px; color: rgb(255, 255, 255); text-rendering: optimizelegibility; font-size: 31.5px; background-color: rgb(18, 20, 23);">Source code

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

#define NAME "net2"
#define UID 997
#define GID 997
#define PORT 2997

void run()
{
unsigned int quad[4];
int i;
unsigned int result, wanted;

result = 0;
for(i = 0; i < 4; i++) {
quad[i] = random();
result += quad[i];

if(write(0, &(quad[i]), sizeof(result)) != sizeof(result)) {
errx(1, ":(\n");
}
}

if(read(0, &wanted, sizeof(result)) != sizeof(result)) {
errx(1, ":<\n");
}


if(result == wanted) {
printf("you added them correctly\n");
} else {
printf("sorry, try again. invalid\n");
}
}

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

这题也是从上一题延伸过来,通过分析题目可以得到程序通过一个for循环生成4个随机数,分4次大小以sizeof(result)发送,用另一个变量来保存4个变量相加的和,如果客户端返回四个数的和相等的数即可。

#!/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))

result = 0
for i in range(4):
rec = s.recv(4)
num = unpack("<I",rec)[0]
print "num[%d]:%d"%(i,num)
result += num
print str(result)

s.send(pack("<I",result))
print s.recv(1024)
s.close()

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=2997,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
num[0]:605764919
num[1]:1932937542
num[2]:278220490
num[3]:835448954
3652371905
you added them correctly




推荐阅读:
  1. Django 模型类(models.py)的定义详解
  2. JVM如何创建对象及访问定位

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

protostar net2 tos st

上一篇:Windows利用Swarm原生Docker集群踩坑总结

下一篇:Biztalk EDI 解决方案

相关阅读

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

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