资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

Protostarnet1

This level is at /opt/protostar/bin/net1

Source code

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

#define NAME "net1"
#define UID 998
#define GID 998
#define PORT 2998

void run()
{
char buf[12];
char fub[12];
char *q;

unsigned int wanted;

wanted = random();

sprintf(fub, "%d", wanted);

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

if(fgets(buf, sizeof(buf)-1, stdin) == NULL) {
errx(1, ":(\n");
}

q = strchr(buf, '\r'); if(q) *q = 0;
q = strchr(buf, '\n'); if(q) *q = 0;

if(strcmp(fub, buf) == 0) {
printf("you correctly sent the data\n");
} else {
printf("you didn't send the data properly\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();
}

这题与上一题其实差不多,上一题是直接将字符串格式的输出,而这道题是以%d出输出。如果在客户端接收到这个%d数字直接输出的话肯定会出现乱码的,因此需要在客户端转化后再输出即可。直接上代码:

#!/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)
num = unpack(" print str(num[0])
buf = num[0]
s.send(str(buf))

print s.recv(1024)


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=2998,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
1436569335
you correctly sent the data









标题名称:Protostarnet1
转载源于:http://cdkjz.cn/article/jgsjsd.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220