/* cgipoison.c: generate junk email addresses for spambot * H.Tsukamoto (h1r.org) */ #include #include #include "buffer.h" #include "env.h" #include "fmt.h" #include "stralloc.h" #include "tai.h" #include "mycgi.h" /* define if your httpd is shttpd or skahttpd */ #define SHTTPD /* mail address for honeypot */ #define LOCAL "poison" #define DOMAIN "example.com" #define COUNT 3000 #define SLEEP 3 #define SAMEDOM 50 #define out(s) buffer_puts(buffer_1,s) const char *st = \ "Content-Type: text/html;charset=EUC-JP\n\n" \ "\n\nDo Mo Ari Gatto Mister Robot.\n" \ "\n" \ "\n\n" \ "\n

毒入りごはん(for spambot)

\n
\n" \ "ロボくん、どうぞめしあがれ!

"; const char *bd1 = "名なしさん@お腹いっぱい
\n"; const char *en = \ "
Script by H.Tsukamoto
Powered by djblib.\n\n\n"; const char *er = \ "

can not get environment variables\n" \ "maybe configration error.

"; /* 20 domains */ const char *dom[] = { \ ".co.jp",".ne.jp",".ad.jp",".or.jp",".gr.jp", ".ed.jp",".ac.jp",".go.jp",".jp",".to", ".com",".net",".org",".gov",".mil", ".info",".firm",".biz",".ac",".cc"}; /* generate random strings */ char *gen_rndstr (register char *s,int len) { char *str; str = s; while (len--){*s++ = rand() % 26 + 'a';} *s = (char) 0; return str; } const char i2h[] = "0123456789ABCDEF"; char *ip2hexstr(char *ip) { static char hx[9]; register char *s; register unsigned int dec; int i; s=hx; for (i = 0; i < 4; i++) { dec = 0; while (*ip >= '0' && *ip <= '9') { dec = dec * 10 + *ip++ - '0'; } *s++ = i2h[dec >> 4]; *s++ = i2h[dec & 0x0f]; ip++; } *s = 0; return (hx); } static struct tai tainow; /* return unix time */ char *now (void) { static char s[16]; fmt_ulong(s,(unsigned long)tainow.x); return s; } /* output message to stderr */ void log_error (const char *s) { buffer_puts(buffer_2,"cgipoison: "); buffer_puts(buffer_2,s); buffer_put(buffer_2,"\n",1); buffer_flush(buffer_2); } void barf_mem(void) { log_error("memory allocation error");} stralloc linebuff = {0}; stralloc d1 = {0}; static int domcount = 0; /* generate mail address */ void genmail (void) { static char d[10]; char *s; if (!stralloc_copys(&linebuff,"")) barf_mem(); if (!stralloc_cats(&linebuff,gen_rndstr(d, 4 + rand() % 5))) barf_mem(); if (!stralloc_cats(&linebuff,"@")) barf_mem(); if (!stralloc_cats(&linebuff,gen_rndstr(d,2 + rand () % 3))) barf_mem(); if (!stralloc_cats(&linebuff,".")) barf_mem(); if (!(domcount++ % SAMEDOM)) { if (!stralloc_copys(&d1,"")) barf_mem(); if (!stralloc_cats(&d1,gen_rndstr(d,6 + rand() % 3))) barf_mem(); s = dom[(rand() % 20)]; if (!stralloc_cats(&d1,s)) barf_mem(); domcount = 1; } if (!stralloc_cat(&linebuff,&d1)) barf_mem(); } /* generate links */ void links (char *s) { char id[5]; if (s) { out("
Links:

\n(;´Д`)


\n"); } } /* generate mail links */ void mail_links(void){ int i; i = COUNT; while (i--) { genmail(); out(""); buffer_put(buffer_1,linebuff.s,linebuff.len); out("
\n"); } } stralloc query = {0}; /* generate trap honeypot address */ void mail_trap(void) { char *s; if (!stralloc_copys(&query,"")) log_error("memory allocation error"); if (s = env_get("QUERY_STRING")) { if (!stralloc_cats(&query,s)) log_error("memory allocation error"); } if (query.len) { log_error("*** Fish On!! ***"); sleep(SLEEP); } else { if (s = env_get("REMOTE_ADDR")) { out(bd1); out(ip2hexstr(s)); out(now()); out(bd2); } else { out(er); log_error("can not get REMOTE_ADDR"); } } } int main(int argc,char **argv) { char *path; tai_now(&tainow); #if defined(SHTTPD) mycgi_header(&tainow); #endif if (!(path = env_get("PATH_INFO"))) { log_error("can not get PATH_INFO"); } out(st); mail_links(); mail_trap(); links(path); out(en); buffer_flush(buffer_1); _exit(0); }