/* cpoison.c: generate junk email addresses for spambot * H.Tsukamoto (h1r.org) */ #include #include #include "buffer.h" #include "env.h" #include "fmt.h" #include "tai.h" #include "stralloc.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 300 #define SLEEP 4 #define SAMEDOM 30 #define out(s) buffer_puts(buffer_1,s) /* EUC: 161 - 254 */ #define RNDKNJ (rand() % (206 - 176 + 1 )) + 176 #define RNDKNJ2 (rand() % (254 - 161 + 1 )) + 161 #define RNDKANA 164 #define RNDKANA2 (rand() % (243 - 161 + 1 )) + 161 #define RNDKATA 165 #define RNDKATA2 (rand() % (243 - 161 + 1 )) + 161 const char *st = \ "Content-Type: text/html;charset=EUC-JP\n\n" \ "\n\nありがたきお言葉\n" \ "\n" \ "\n\n" \ "\n

ありがたきお言葉

\n" \ "注:このページはメールアドレスを拾うロボットくん専用です。
\n"; const char *bd1 = "
作者より
\n" \ "逝ってください
\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",".fm",".biz",".ac",".cc"}; /* 20 */ const char *setsubi[] = {"ソリューション","センター"," 株式会社", "メムバー"," 部長", "テクノロジー"," 族","システムズ","コーポレーション"," 事務所", "ソフトウェア","組・若頭"," ちゃん"," 党本部"," 先生", "大学"," 教・教祖","さん","メンバー","の母"}; /* 30 */ const char *joshi[] = {"は","な","の","が","を", "する","に","してる","かもしれない。","してても、", "に","するときに、","のような","のように","のようだ。", "だとしても、","から","と思われ、","するとは、","であるし、", "から","のままで、","だけれど","だから","のために", "なので、","だが、","のために","であるが、","なのか。"}; stralloc linebuff = {0}; /* 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");} /* 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; } #define R_KANJI 0 #define R_KANA 1 #define R_KATA 2 void rndjpn(const int t, int len) { static char s[3] = {0,0,0}; while (len--) { if (t == R_KANJI) { s[0] = RNDKNJ; s[1] = RNDKNJ2; } else { if (t == R_KANA) { s[0] = RNDKANA; } else { s[0] = RNDKATA; } s[1] = RNDKANA2; } if(!stralloc_cats(&linebuff,s)) barf_mem(); } } void rnd_bun() { int i; i = 5; if (!stralloc_copys(&linebuff,"")) barf_mem(); while(i--) { if (rand() % 10) { rndjpn(R_KANJI, rand() % 2 + 1); } else { rndjpn(R_KATA, rand() % 5 + 3); } if (!stralloc_cats(&linebuff,joshi[rand() % 30])) barf_mem(); } if (!stralloc_cats(&linebuff,"\n")) barf_mem(); } static struct tai tainow; /* return unix time */ char *now (void) { static char s[16]; fmt_ulong(s,(unsigned long)tainow.x); return s; } 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 gen_body(void){ int i; i = COUNT; while (i--) { genmail(); out("
\n"); stralloc_copys(&linebuff,""); switch (rand() % 5) { case 0: rndjpn(R_KATA, rand() % 5 + 3); break; case 1: case 2: rndjpn(R_KANA, rand() % 5 + 2); break; default: rndjpn(R_KANJI, rand() % 3 + 2); break; } stralloc_cats(&linebuff,setsubi[rand() % 20]); buffer_put(buffer_1,linebuff.s,linebuff.len); out("
\n"); rnd_bun(); buffer_put(buffer_1,linebuff.s,linebuff.len); out("
\n"); } } 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); } stralloc query = {0}; /* generate trap honeypot address */ void mail_trap(void) { char *s; if (!stralloc_copys(&query,"")) barf_mem(); if (s = env_get("QUERY_STRING")) { if (!stralloc_cats(&query,s)) barf_mem(); } 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); srand(tainow.x); #if defined(SHTTPD) mycgi_header(&tainow); #endif if (!(path = env_get("PATH_INFO"))) { log_error("can not get PATH_INFO"); } out(st); gen_body(); mail_trap(); links(path); out(en); buffer_flush(buffer_1); _exit(0); }