Tuesday, December 20, 2011

Email Harvesting with PHP and Javascript

We can scrape emails using the prototype library and php.. like so..

1:  <script src="prototype.js"></script>  
2:  <script>  
3:       function scrapeEmails(url)  
4:       {  
5:            var notice = $('notice');  
6:            var url = 'proxy.php?url=' + encodeURIComponent(url);  
7:            new Ajax.Request(url,  
8:            {  
9:                 method: 'get',  
10:                 onSuccess: function(transport)  
11:                 {  
12:                      var markdown = transport.responseText;  
13:                      markdown.gsub(/\w+@\w+[.]\w+/g, function(matches)  
14:                      {  
15:                           //var emails = matches.split(',');  
16:                           for(i=0;i<matches.length;i++)  
17:                           {  
18:                                notice.insert(matches[i] + "<br/>");  
19:                           }  
20:                      });  
21:                 },  
22:                 onFailure: function(transport)  
23:                 {  
24:                      notice.update(transport.responseText);  
25:                 }  
26:            });  
27:       }  
28:  </script>  

And the proxy.php ifile (while vulnerable to file inclusion at this point, please secure your own scripts and stop bitching at me)

1:  <?php  
2:  $url = $_GET['url'];  
3:  $content = file_get_contents($url);  
4:  header('Content-type: text/xml');  
5:  echo $content;  
6:  ?>  

And use it like this..

1:  <body>  
2:       <input type="text" value="http://www.dotfart.com/quiz/emails.txt" size="80" id="url">  
3:       <input type="button" value="do it" onclick="scrapeEmails(document.getElementById('url').value);">  
4:       <hr/>  
5:       <div id="notice"></div>  
6:  </body>  

Toggling DIV's with Prototype

1:  <script src="prototype.js"></script>  
2:  <script>  
3:       //exmaple: toggleDivs('myDiv,OtherDiv');  
4:       function toggleDivs(divs)  
5:       {  
6:            var divSplit = divs.split(",");  
7:            for(i=0;i<divSplit.length;i++)  
8:            {  
9:                 var d = $(divSplit[i]);  
10:                 if($(d).visible())  
11:                 {  
12:                      d.hide();  
13:                 } else {  
14:                      d.show();  
15:                 }  
16:            }  
17:       }  
18:       //example: checkForm('myForm');  
19:       function checkForm(frm)  
20:       {  
21:            allFields = Form.getElements("myForm");  
22:            for(i=0;i<allFields.length;i++)  
23:            {  
24:                 if(allFields[i].value == "")  
25:                 {  
26:                      $(allFields[i]).addClassName('error');  
27:                 } else {  
28:                      $(allFields[i]).removeClassName('error')  
29:                 }  
30:            }  
31:       }  
32:  </script>  

Simple Form Validation with Prototype

1:  <script src="prototype.js"></script>  
2:  <script>  
3:    //example: checkForm('myForm');  
4:    function checkForm(frm)  
5:    {  
6:      allFields = Form.getElements("myForm");  
7:      for(i=0;i<allFields.length;i++)  
8:      {  
9:        if(allFields[i].value == "")  
10:        {  
11:          $(allFields[i]).addClassName('error');  
12:        } else {  
13:          $(allFields[i]).removeClassName('error')  
14:        }  
15:      }  
16:    }  
17:  </script>