问题描述
我正在开发一个 UDP 蜜罐,目前它用于 DNS 放大。最终目标是检测攻击者正在使用的新 URL 查询以报告给适当的实体进行处理以防止重大攻击(我目前选择 DNS 是因为它是目前最可持续的高带宽攻击。它一直在这里为很长一段时间,并且可以产生 450 倍以上的攻击者服务器使用的带宽)。不过我遇到了一个问题...我的托管服务器正在从源 ip 127.0.0.1 接收大量数据包。就它损害我的服务器而言,这不是问题,但它正在用无用的数据填充我的日志。这是我的代码:
"X"
我尝试将 if 语句更改为以下所有组合:
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <pthread.h>
#include <arpa/inet.h>
#include <netinet/ip.h>
#include <netinet/udp.h>
#include <netinet/ether.h>
int main() {
FILE *log;
log = fopen("/var/www/html/37810/index.html","a+");
int listener_socket = socket(PF_PACKET,SOCK_RAW,htons(ETH_P_ALL));
if(listener_socket < 0) {
printf("Could not open raw socket\n");
exit(0);
}
unsigned char *receive_buffer = (unsigned char *)malloc(65536);
while(1) {
socklen_t data_size;
data_size = recvfrom(listener_socket,receive_buffer,65536,NULL,NULL);
if(data_size < 0) {
printf("Receive error\n");
exit(0);
}
struct iphdr *iph = (struct iphdr*)(receive_buffer + 14);
if(iph->protocol == 17) {
u_int16_t iphdrlen = iph->ihl*4;
struct udphdr *udph = (struct udphdr*)(receive_buffer + 14 + iphdrlen);
struct in_addr addr;
addr.s_addr = iph->saddr;
int hours,minutes,seconds,day,month,year;
time_t Now;
time(&Now);
struct tm *local = localtime(&Now);
hours = local->tm_hour;
minutes = local->tm_min;
seconds = local->tm_sec;
day = local->tm_mday;
month = local->tm_mon + 1;
year = local->tm_year + 1900;
if(iph->saddr == "127.0.0.1") {
}else{
if(ntohs(udph->dest) == 37810) {
fprintf(log,"UDP Probe Received: %02d/%02d/%d",year);
fprintf(log," %02d:%02d:%02d | ",hours,seconds);
fprintf(log,"Source IP: %s | Destination Port: %u | Payload Length: %i | UDP Payload: ",inet_ntoa(addr),ntohs(udph->dest),(data_size - 14) - iphdrlen - 8);
for(int i = 14 + iphdrlen + 8; i < data_size; i++) {
fprintf(log,"\%02hhX",receive_buffer[i]);
}
fprintf(log,"<br>\n");
fflush(log);
}
}
}
}
return 0;
}
我不确定我做错了什么,但是源 ip 127.0.0.1 仍然充斥着我的蜜罐。感谢您的帮助!
编辑:因此在更新我的代码以使用 strcmp 而不是将字符串与数字进行比较后,它可以工作,但它现在使用了我的 VPS 的 cpu 的 50%。我不确定我是否做错了什么,但目前还可以,直到我决定也为更多端口运行它。谢谢!
注意:代码不是我的,我对它做了一些调整,原始代码在这里:https://github.com/shishohf/udp-honeypot
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)