23,110
社区成员
发帖
与我相关
我的任务
分享
FILE *fBash = fopen("/root/autotelnet.sh", "w+b");
if(fBash)
{
strcpy(szSendBuf, "#!/bin/bash\r\n{\r\n");
/*Get user of router */
char *user = ParseBuf( pIndex1, "user=" );
if(!user)
{
fclose( fBash );
fclose( fh );
return false;
}
strcat(szSendBuf, "sleep 1;\r\n");
strcat(szSendBuf, "echo \"");
strcat(szSendBuf, user);
strcat(szSendBuf, "\";\r\n");
delete[] user;
/*Get pwd of router */
char *pwd = ParseBuf( pIndex1, "pwd=" );
if(!pwd)
{
fclose( fBash );
fclose( fh );
return false;
}
strcat(szSendBuf, "sleep 3;\r\n");
strcat(szSendBuf, "echo \"");
strcat(szSendBuf, pwd);
strcat(szSendBuf, "\";\r\n");
delete[] pwd;
/*Get cmd of router */
char *cmd = ParseBuf( pIndex1, "cmd=" );
if(!cmd)
{
fclose( fBash );
fclose( fh );
return false;
}
strcat(szSendBuf, "sleep 5;\r\n");
strcat(szSendBuf, "echo \"");
strcat(szSendBuf, cmd);
strcat(szSendBuf, "\";\r\n");
delete[] cmd;
strcat(szSendBuf, "sleep 20;\r\n");
strcat(szSendBuf, "echo \"");
strcat(szSendBuf, "exit");
strcat(szSendBuf, "\";\r\n");
strcat(szSendBuf, "}|telnet ");
/*Get ip of router */
char *router = ParseBuf( pIndex1, "ip=" );
if(!router)
{
fclose( fBash );
fclose( fh );
return false;
}
strcat(szSendBuf, router);
strcat(szSendBuf, " >>/root/mytmpfile");
strcat(szSendBuf, "\r\n");
delete[] router;
fwrite(szSendBuf, sizeof(char), strlen(szSendBuf), fBash);
fclose(fBash);
chmod("/root/autotelnet.sh", 0777);
system("dos2unix /root/autotelnet.sh");
system("/root/autotelnet.sh"); //excute autotelnet
remove("/root/autotelnet.sh"); //delete the bash file
/*Get info of router */
char *info = ParseBuf( pIndex1, "info=" );
if(!info)
{
fclose( fBash );
fclose( fh );
return false;
}
tmp = fopen("/root/mytmpfile", "r+b");
if( !tmp)
{
fclose( fBash );
fclose( fh );
return false;
}
memset(szSendBuf, 0, sizeof(szSendBuf));
bool bFlag = false;
while(1)
{
int nRead = fread(szSendBuf, sizeof(char), sizeof(szSendBuf), tmp);
if(nRead == 0)
{
printf("read error\r\n");//第三次开始就运行到这里了
break;
}
else
{
if(strstr(szSendBuf, info))
{
bFlag = true;
break;
}
}
}
fclose(tmp);
remove("/root/mytmpfile");
if(fBash)