<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Digital Offensive &#187; Code</title>
	<atom:link href="http://www.digitaloffensive.com/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.digitaloffensive.com</link>
	<description>Take an offensive approach to Security know what your foes know!</description>
	<lastBuildDate>Fri, 27 Jan 2012 18:53:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Ruby: Script to check if an IP is up and get its Hostname</title>
		<link>http://www.digitaloffensive.com/2012/01/ruby-script-to-check-if-an-ip-is-up-and-get-its-hostname/</link>
		<comments>http://www.digitaloffensive.com/2012/01/ruby-script-to-check-if-an-ip-is-up-and-get-its-hostname/#comments</comments>
		<pubDate>Fri, 27 Jan 2012 18:53:39 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://www.digitaloffensive.com/?p=372</guid>
		<description><![CDATA[Ruby: Script to check if an IP is up and get its Hostname This script will go line by through a text file checking to see which IP is up. If the host is not up it will log to the results.csv file as “IP,DOWN,NoName”. If the host is up it will log to the [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Ruby: Script to check if an IP is up and get its Hostname</strong></p>
<p>This script will go line by through a text file checking to see which IP is up. If the host is not up it will log to the results.csv file as “IP,DOWN,NoName”. If the host is up it will log to the results.csv file as “IP,UP,hostname”. Please note that if the authority DNS server does not have an answer for that IP it will log no name and instead will put the IP address again.  This script is very handy on our firewall audits and cleans ups to see what hosts are still needed and which are no longer even turned on any longer.</p>
<p>You will need to have the IP addresses you want to check in a file called IP.txt, unless you edit the script. Make sure you put the file in the same path as the script.</p>
<blockquote><p>#!/usr/bin/ruby<br />
require &#8220;socket&#8221;<br />
require &#8216;resolv&#8217;</p>
<p>def computer_exists?(fwip)<br />
system(&#8220;ping -c1 -w1 #{fwip}&#8221;)<br />
end</p>
<p>def append_to_file(line)<br />
file = File.open(&#8220;results.csv&#8221;, &#8220;a&#8221;)<br />
file.puts(line)<br />
file.close<br />
end</p>
<p>def getInfo(current_ip)<br />
begin<br />
if computer_exists?(current_ip)<br />
host_name = Socket.getaddrinfo(current_ip,nil)<br />
append_to_file(&#8220;#{current_ip},UP,#{host_name[0][2]}\n&#8221;)<br />
else<br />
append_to_file(&#8220;#{current_ip},DOWN,NoNAME\n&#8221;)<br />
end<br />
rescue SocketError =&gt; mySocketError<br />
append_to_file(&#8220;#{current_ip},UP,ERROR&#8221;)<br />
end<br />
end</p>
<p>#Myfavorite method, read and process file<br />
ipLST=&#8217;IP.txt&#8217;<br />
File.readlines(ipLST).each do |line|<br />
current_ip = &#8220;#{line}&#8221;<br />
getInfo(current_ip)<br />
end</p></blockquote>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.digitaloffensive.com%2F2012%2F01%2Fruby-script-to-check-if-an-ip-is-up-and-get-its-hostname%2F&amp;title=Ruby%3A%20Script%20to%20check%20if%20an%20IP%20is%20up%20and%20get%20its%20Hostname" id="wpa2a_2"><img src="http://www.digitaloffensive.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.digitaloffensive.com/2012/01/ruby-script-to-check-if-an-ip-is-up-and-get-its-hostname/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple powershell script to automate Acuentix command line scans</title>
		<link>http://www.digitaloffensive.com/2011/09/simple-powershell-script-to-automate-acuentix-command-line-scans/</link>
		<comments>http://www.digitaloffensive.com/2011/09/simple-powershell-script-to-automate-acuentix-command-line-scans/#comments</comments>
		<pubDate>Fri, 23 Sep 2011 18:09:16 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://www.digitaloffensive.com/?p=356</guid>
		<description><![CDATA[Simple powershell script to automate Acuentix command line scans: Requirements: 1. Windows vista or higher (preferably 7) 2. Powershell 2,0 3. user access control disabled 4. Acuentix installed (v7 or higher) 5. List of sites to scan Adding functionality: To add functions to the wvs_console call edit the variable $scan Code: ################################################ ## Automate Acunetix [...]]]></description>
			<content:encoded><![CDATA[<p><strong><span style="color: #000000;"><span style="font-family: Georgia,'Times New Roman','Bitstream Charter',Times,serif;">Simple powershell script to automate Acuentix command line scans</span></span>:</strong></p>
<p><strong>Requirements:</strong><br />
1. Windows vista or higher (preferably 7)<br />
2. Powershell 2,0<br />
3. user access control disabled<br />
4. Acuentix installed (v7 or higher)<br />
5. List of sites to scan</p>
<p><strong>Adding functionality:</strong></p>
<p>To add functions to the wvs_console call edit the variable $scan</p>
<p><strong>Code:</strong></p>
<blockquote><p>################################################<br />
## Automate Acunetix Console Scans<br />
## Edit $scan to add more function (profile, report type, etc)<br />
## Created by Michael LaSalvia<br />
## http://www.digitaloffensive.com for http://SecurityonLocation.com<br />
###############################################</p>
<p>Set-Location &#8220;C:\Program Files (x86)\Acunetix\Web Vulnerability Scanner 7&#8243;<br />
# Add my directory to the current PATH<br />
$x = (Get-Location).ProviderPath<br />
$env:path = &#8220;$env:path;$x&#8221;<br />
write-host &#8220;Current directory added to ENV:PATH&#8221;<br />
##################################################<br />
##Edit below but be careful<br />
##################################################</p>
<p>$sites= Get-Content c:\mytest\sites.txt<br />
foreach ($i in $sites) {<br />
$scan = &#8220;/scan $i /generatereport&#8221;<br />
Start-Process &#8216;wvs_console.exe&#8217; -WindowStyle hidden -Wait -ArgumentList $scan -PassThru</p>
<p>}<br />
exit</p></blockquote>
<p><strong>How to run:</strong></p>
<p>Place code in a file called whatever you want .ps1 and make sure to sign so you can execute it with powershell. Also make sure to edit the variable sites and variable scan to meet your requirements.</p>
<p>Any questions or concerns feel free to contact me.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.digitaloffensive.com%2F2011%2F09%2Fsimple-powershell-script-to-automate-acuentix-command-line-scans%2F&amp;title=Simple%20powershell%20script%20to%20automate%20Acuentix%20command%20line%20scans" id="wpa2a_4"><img src="http://www.digitaloffensive.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.digitaloffensive.com/2011/09/simple-powershell-script-to-automate-acuentix-command-line-scans/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple Ruby banner grabber and port checker</title>
		<link>http://www.digitaloffensive.com/2011/07/simple-ruby-banner-grabber-and-port-checker/</link>
		<comments>http://www.digitaloffensive.com/2011/07/simple-ruby-banner-grabber-and-port-checker/#comments</comments>
		<pubDate>Mon, 18 Jul 2011 16:44:03 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://www.digitaloffensive.com/?p=348</guid>
		<description><![CDATA[Simple Ruby banner grabber and port checker: This is a simple script I wrote in ruby to scan ports to see if they are open and grab the banner of the service.  The script has error handling built in so it is able to continue on to the next port if the port before is [...]]]></description>
			<content:encoded><![CDATA[<p>Simple Ruby banner grabber and port checker:</p>
<p>This is a simple script I wrote in ruby to scan ports to see if they are open and grab the banner of the service.  The script has error handling built in so it is able to continue on to the next port if the port before is closed. Port banners are displayed to the screen. If you want to log them to a file just alter the print statement to redirect to a file. To change the port ranges to scan alter the line where the “for loop” is 0…65536. This script will only do tcp and not udp. The script was written for fun but when you are doing an actual audit sometimes you cannot install tools on the machines or with in the network you are auditing. This will allow you to use a piece of software that is installed on most new Linux machines.</p>
<p><span id="more-348"></span></p>
<p>#!/usr/bin/ruby<br />
#Simple Ruby Banner Graber<br />
#Created by Mike @ digitaloffensive.com<br />
#######################################</p>
<p>require &#8216;socket&#8217;<br />
puts &#8220;Enter the IP to scan: &#8221;<br />
bIps = gets<br />
puts &#8220;Now scanning #{bIps} for open ports&#8221;<br />
for sPorts in 0&#8230;65536<br />
begin<br />
bcon = TCPsocket.new(&#8220;#{bIps}&#8221;, &#8220;#{sPorts}&#8221;)<br />
bcon.puts(&#8220;get / HTTP/1.1 \n\n\n\n\n&#8221;) #http is picky<br />
bhead = bcon.recv(100)<br />
bcon.close<br />
print bhead<br />
rescue<br />
puts &#8220;#{sPorts} is not open, continuing&#8221;<br />
end<br />
end</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.digitaloffensive.com%2F2011%2F07%2Fsimple-ruby-banner-grabber-and-port-checker%2F&amp;title=Simple%20Ruby%20banner%20grabber%20and%20port%20checker" id="wpa2a_6"><img src="http://www.digitaloffensive.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.digitaloffensive.com/2011/07/simple-ruby-banner-grabber-and-port-checker/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Detecting malicious code in webpages iScanner and iScan Script</title>
		<link>http://www.digitaloffensive.com/2011/03/detecting-malicious-code-in-webpages-iscanner-and-iscan-script/</link>
		<comments>http://www.digitaloffensive.com/2011/03/detecting-malicious-code-in-webpages-iscanner-and-iscan-script/#comments</comments>
		<pubDate>Wed, 30 Mar 2011 13:53:10 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://www.digitaloffensive.com/?p=327</guid>
		<description><![CDATA[Detecting malicious code in webpages iScanner and iScan Script iScanner is developed by the folks over at iSecur1ty.org. The latest update of code was in September of 2010. The iScanner application is ruby based application that has many features: Current Features: Ability to scan one file, directory or remote web page / website. Detect and [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Detecting malicious code in webpages iScanner and iScan Script</strong></p>
<p>iScanner is developed by the folks over at iSecur1ty.org. The latest update of code was in September of 2010. The iScanner application is ruby based application that has many features:</p>
<p><strong>Current Features:</strong></p>
<ul>
<li>Ability to scan one file, directory or remote web page / website.</li>
<li>Detect and remove website malwares and malicious code in web pages. This include hidden iframe tags, javascript, vbscript, activex objects, suspicious PHP codes and some known malwares.</li>
<li>Extensive log shows the infected files and the malicious code.</li>
<li>Support for sending email reports.</li>
<li>Ability to clean the infected web pages automatically.</li>
<li>Easy backup and restore system for the infected files.</li>
<li>Simple and editable signature based database.</li>
<li>You can easily send malicious file to iScanner developers for analyzes.</li>
<li>Ability to update the database and the program easily from iScanner&#8217;s server.</li>
<li>Very flexible options and easy to use.</li>
<li>Fast scanner with great performance.</li>
<li>Yes, it&#8217;s FREE!!</li>
</ul>
<p>I found this tool extremely interesting and started playing with it. Overall it is a great tool though I found it was missing some functionality that I wanted.</p>
<p><span id="more-327"></span></p>
<p>1.       It does not have a flag to index and scan the whole site for malicious code.</p>
<p>2.       The database is extremely small and does not detect some common variations of C99 shell.</p>
<p>To resolve the first issue I used the ruby module Hawler and a modified version of htmap created by John Hart of Spoofed.org. This allowed me to get an index of all links that are linked to on the URL you want to scan. Once I had that information I was able to create a simple shell script to loop through the list scanning each page. I even went as far as to only output the infected pages into a report for easy reference.</p>
<p>To resolve the second issue I created my own database based on information I found on the internet and from personal research. I found using a web tool like Rubular, <a href="http://www.rubular.com/">http://www.rubular.com/</a> great for testing my regex strings.  We also are experimenting with downloading known malicious URL lists and auto creating signatures to use in the scans. We will be releasing this code in our next article.</p>
<p>For testing purposes we created the following signature and added it to the database:</p>
<p>a)      &#8212; 9.3</p>
<p>b)       - (eval)</p>
<p>c)       &#8211; PHP &#8216;eval&#8217; functions detected, possible encoded malicious code.</p>
<p>d)      &#8211; MU:RE</p>
<p>&nbsp;</p>
<ul>
<li>Bullet (a) is he signature number; this should be unique for your reporting.</li>
<li>Bullet (b) is the regex string. The regex string is encapsulated in ()</li>
<li>Bullet (c) is a comment about the malicious code.</li>
<li>Bullet (d) tells the app to scan multiple lines to match the regex and to also check when remotely scanning</li>
</ul>
<p>For more information of the creation of custom signature files check out the README file that comes with iScanner it is extremely easy to follow.</p>
<p><strong>So let’s take a look how to install all of this and how to use iScan script:</strong></p>
<p>1.       Make sure you are running linux and have ruby installed or the ability to install ruby.</p>
<p>2.       Install the Hawler ruby gem: gem install &#8211;source <a href="http://spoofed.org/files/hawler/">http://spoofed.org/files/hawler/</a> if any dependencies are needed make sure you install them as well.</p>
<p>3.       Download the modified version of htmp and iscan.sh (found in the zip file with the rest of the scripts from this article).<a title="http://www.digitaloffensive.com/files/iscan.zip" href="http://www.digitaloffensive.com/files/iscan.zip" target="_blank">http://www.digitaloffensive.com/files/iscan.zip</a></p>
<p><cite>4. </cite>Download iScanner from: <a href="http://iscanner.isecur1ty.org/">http://iscanner.isecur1ty.org</a><cite></cite></p>
<p><cite>5. </cite><cite>Uncompress iScanner and run the installer.</cite><cite></cite></p>
<p>6.       Copy iscan.sh to the directory you want to run it from and edit the variables to suit your need.</p>
<p>7.       chmod 777 iscan.sh and run it by typing ./iscan.sh and follow the onscreen directions.</p>
<p>a.       Using the Hawler gem and the modified htmap you will be able to scan all links on the url you enter as well as set how deep you want to crawl. Remember the deeper the longer it will take.</p>
<p><strong>Now that we have all the tools we need let’s create a test environment:</strong></p>
<p>1.       You will need a website for this to work. If you do not have one you can install and run apache on the Linux box that you are working on to use this script.</p>
<p>2.       Create a index page in the root of the web directory with a single href code to test.html</p>
<p>3.       Create another file called test.html and put the word eval in it and anything else you want.</p>
<p>4.       Put my test signature in the signature database and save.</p>
<p>5.       Run the iScan script and follow prompts.</p>
<p>a.       You will be first prompted for the URL. Use the full domain or the IP here. IE <a href="http://www.domain.com/">www.domain.com</a>, domain.com, or 127.0.0.1 avoid using /.</p>
<p>b.      Enter the depth you want to scan. Since this is a test set it to 1</p>
<p>c.       Sit back and watch</p>
<p>This script is pretty basic we are working on making reporting better as well as adding the ability to grab known malicious url black lists and hopefully know malicious code samples and increasing the signature database. The only current down side we see in the iScanner app after using our script is the lack to scan for malicious code in a database.</p>
<p>If you have comments or questions let me know.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.digitaloffensive.com%2F2011%2F03%2Fdetecting-malicious-code-in-webpages-iscanner-and-iscan-script%2F&amp;title=Detecting%20malicious%20code%20in%20webpages%20iScanner%20and%20iScan%20Script" id="wpa2a_8"><img src="http://www.digitaloffensive.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.digitaloffensive.com/2011/03/detecting-malicious-code-in-webpages-iscanner-and-iscan-script/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>MJSIP version 2.0 Beta: Automating the Magic Jack SIP retrieval</title>
		<link>http://www.digitaloffensive.com/2010/10/mjsip-version-2-0-beta-automating-the-magic-jack-sip-retrieval/</link>
		<comments>http://www.digitaloffensive.com/2010/10/mjsip-version-2-0-beta-automating-the-magic-jack-sip-retrieval/#comments</comments>
		<pubDate>Fri, 22 Oct 2010 16:44:47 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://www.digitaloffensive.com/?p=293</guid>
		<description><![CDATA[MJSIP version 2.0 Beta: Automating the Magic Jack SIP retrieval What is MJSIP version 2.0 beta: After a very successful following our first version and recent changes to how Magic Jack is handling passwords and usernames we have decided to update our script with additional filters and added the ability to find your username as [...]]]></description>
			<content:encoded><![CDATA[<p><strong>MJSIP version 2.0 Beta: <strong>Automating the Magic Jack SIP retrieval</strong></strong></p>
<p><strong>What is MJSIP version 2.0 beta:</strong></p>
<p>After a very successful following our first version and recent changes to how Magic Jack is handling passwords and usernames we have decided to update our script with additional filters and added the ability to find your username as well since it is not always E_number_01.</p>
<p><span id="more-293"></span></p>
<p><strong>What is new and why is this called beta:</strong></p>
<p>Though we have tested this on over 40 + jacks from 10/20/2010 to as recently as of today we are have not allowed the general public to try it until now. That is why it is called beta. This version now includes the ability to retrieve your username.</p>
<p><strong><span style="text-decoration: underline;">What is required:</span></strong></p>
<p><strong>MJSIP: </strong>Our Perl script. This can be downloaded here: <a href="http://www.digitaloffensive.com/mj/mjsip2.zip" target="_blank">http://www.digitaloffensive.com/mj/mjsip2.zip</a>. If you have our older ne overwrite it with this one.</p>
<p><strong>SIPDump: </strong>Magic Jack stores all your SIP information in the programs memory during the startup process. SIPDump is a modified version of MemDump, which was originally developed by Stroth. You can download this tool here: <a href="http://www.digitaloffensive.com/mj/mj.rar" target="_blank">http://www.digitaloffensive.com/mj/mj.rar</a></p>
<p><strong>Active Perl:</strong> This is a free windows port of the Perl interpreter. It can be downloaded her for the 32 bit or 64 bit processor: <a href="http://www.activestate.com/activeperl/downloads">http://www.activestate.com/activeperl/downloads</a>. Download the msi file and install it, choose all the defaults.</p>
<p><strong><span style="text-decoration: underline;">How to use it:</span></strong></p>
<p><strong>Step 1: </strong>Download and extract all your tools to a folder on your system. Working out of one folder will make life so much easier.</p>
<p><strong>Step 2: </strong>Use SIPDump.exe to dump the Memory of your Magic Jack. If you need more details on how to do this check out my article on this located here: <a href="http://www.digitaloffensive.com/2010/03/hacking-the-magic-jack-in-2010-for-use-on-trixbox-or-any-other-sip-device/" target="_blank">http://www.digitaloffensive.com/2010/03/hacking-the-magic-jack-in-2010-for-use-on-trixbox-or-any-other-sip-device/</a></p>
<p><strong>Step3: </strong>Out of all the Magic Jack’s we have tested the 3<sup>rd</sup> dump file was the most reliable at containing the password. I would strongly suggest you do not change that line in the MJSIP.pl file.</p>
<p><strong>Step 4: </strong>Open a command prompt and navigate to the folder that you created that has all your tools in it. This folder should also contain you SIPDump files, unless you did not listen to my suggestions above. Once in that folder type the following command “perl mjsip.pl” This should dump your password and username to the screen.</p>
<p style="text-align: center;"><a href="http://www.digitaloffensive.com/wp-content/uploads/2010/10/mjsip2.jpg"><img class="aligncenter size-medium wp-image-294" title="mjsip2" src="http://www.digitaloffensive.com/wp-content/uploads/2010/10/mjsip2-300x108.jpg" alt="" width="300" height="108" /></a></p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.digitaloffensive.com%2F2010%2F10%2Fmjsip-version-2-0-beta-automating-the-magic-jack-sip-retrieval%2F&amp;title=MJSIP%20version%202.0%20Beta%3A%20Automating%20the%20Magic%20Jack%20SIP%20retrieval" id="wpa2a_10"><img src="http://www.digitaloffensive.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.digitaloffensive.com/2010/10/mjsip-version-2-0-beta-automating-the-magic-jack-sip-retrieval/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>SIPBAN for APF</title>
		<link>http://www.digitaloffensive.com/2010/10/sipban-for-apf/</link>
		<comments>http://www.digitaloffensive.com/2010/10/sipban-for-apf/#comments</comments>
		<pubDate>Tue, 19 Oct 2010 23:53:22 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://www.digitaloffensive.com/?p=289</guid>
		<description><![CDATA[SIPBAN v1.0 What is SIPBAN: SIPBAN is an addon for the advance policy firewall written by “R-FX Networks (http://www.rfxn.com)”. This addon is will search your asterisk logs for failed registration attempts from unknown networks and ban the IP address. This helps thwart SIP secret guessing and other SIP based attacks. How to configure and use [...]]]></description>
			<content:encoded><![CDATA[<p><strong>SIPBAN v1.0</strong></p>
<p><strong>What is SIPBAN:</strong></p>
<p>SIPBAN is an addon for the advance policy firewall written by “R-FX Networks (<a href="http://www.rfxn.com">http://www.rfxn.com</a>)”. This addon is will search your asterisk logs for failed registration attempts from unknown networks and ban the IP address. This helps thwart SIP secret guessing and other SIP based attacks.</p>
<p><span id="more-289"></span></p>
<p><strong>How to configure and use the script:</strong></p>
<p>Configuration of the script is done by variables. The most important variables are gIP1 and gIP2. These variables are where you can define friendly networks not to ban. For example your work network is 192.168.2.x. So gIP1 would look like this gIP1=192.168.2. You could do just 192.168 but that leaves a lot of room for IP spoofing even though that is a RFC 1918 IP. You can use gIP2 for your home network or a remote office. To add more friendly networks just add more gIP variables in the variable section and edit line 15 of the script by adding an addition “ | grep –v “$gIP#” to the line right after the last one. Repeat this as much as you need to.</p>
<p>Once you made those changes save the script and change the permission of the script using chmod so it now executable.</p>
<p>Before you execute the script make sure you have “APF” installed and configured to your requirements. To configure APF for use in a PBX in environment leave egress filtering to  “0” as in disabled and set ingress filtering to TCP 22, 80 and UDP 5060_6000 and 10000_20000. Once that is done make sure that APF is still in development mode . This insures that if you ban yourself or if you did not set the ports right you will be able to get back in after 5 minutes. Finally start APF by issuing the command apf –s.</p>
<p>Now that APF is running run a test of SIPBAN. To do this run the command ./sipban.sh. Nothing will show on the screen. Once it returns back to a command line you can view the log at /var/tmp/sipban.log. If everything looks successful then you can edit the APF config to take it out of development mode and restart APF.</p>
<p>At this point you are ready to schedule SIPBAN via the cron to run on whatever cycle you want. Since it is parsing a large log file I would do a minimum of 1 hour depending on how much ram your PBX has.</p>
<p>0 * * * * /root/sipban.sh</p>
<p><strong>Where to get SIPBAN:</strong></p>
<p>To get a copy of SIPBAN click the following link <a href="http://www.digitaloffensive.com/files/sipban.sh">http://www.digitaloffensive.com/files/sipban.sh</a></p>
<p>If you have any questions or comments please feel free to contact us.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.digitaloffensive.com%2F2010%2F10%2Fsipban-for-apf%2F&amp;title=SIPBAN%20for%20APF" id="wpa2a_12"><img src="http://www.digitaloffensive.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.digitaloffensive.com/2010/10/sipban-for-apf/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>AutoRAFI (Automatic Remote Asterisk and FreePBX  Install) for Fedora and CentOS</title>
		<link>http://www.digitaloffensive.com/2010/10/autorafi-automatic-remote-asterisk-and-freepbx-install-for-fedora-and-centos/</link>
		<comments>http://www.digitaloffensive.com/2010/10/autorafi-automatic-remote-asterisk-and-freepbx-install-for-fedora-and-centos/#comments</comments>
		<pubDate>Tue, 05 Oct 2010 00:43:06 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://www.digitaloffensive.com/?p=282</guid>
		<description><![CDATA[AUTORAFI (Automatic Remote Asterisk and FreePBX Install) About: AUTORAFI is a Linux shell script developed by Digital Offensive to either locally or remotely install an Asterisk based PBX solution with FreePBX front end. AUTORAFI was developed and tested on base installs of CentOS and Fedora Core. Why: Over the last few years we have been [...]]]></description>
			<content:encoded><![CDATA[<p><strong>AUTORAFI (Automatic Remote Asterisk and FreePBX  Install)</strong></p>
<p><strong>About:</strong><br />
AUTORAFI is a Linux shell script developed by Digital Offensive to either locally or remotely install an Asterisk based PBX solution with FreePBX front end.  AUTORAFI was developed and tested on base installs of CentOS and Fedora Core.<br />
<span id="more-282"></span><br />
<strong>Why:</strong><br />
Over the last few years we have been installing more and more of these solutions so we have taken the time to automate as much as we can to save time. Now we are offering AUTORAFI to the general public to make your lives easier.</p>
<p><strong>Requirements:</strong><br />
1.	System running either CentOS or Fedora Core.<br />
2.	SSH or console access<br />
3.	root access<br />
4.	Basic knowledge of Linux text editors<br />
5.	Internet access<br />
6.	Patience: install can take up to 1 ½ hours depending on your internet connection and your system configuration.<br />
7.	If you are running behind a firewall you will need to review this article for special firewall and FreePBX configuration: http://www.digitaloffensive.com/2010/05/overcoming-sip-over-nat</p>
<p><strong>Use:</strong><br />
1.	Copy the script to your server.<br />
2.	Use your favorite Linux text editor to change the user variables<br />
      a. Uncomment the following sections if they apply to you<br />
           i.Webmin: Lines  112-114<br />
           ii.DAHDI:  Lines 180-185<br />
3.	Make sure it has a .sh extension<br />
4.	Chmod 777 script_name.sh<br />
5.	./script_name.sh<br />
6.	Follow prompts!!<br />
        a. If you see warnings it is ok to proceed. It is when you see major errors, or failures that you need to stop the install.</p>
<p><strong>Cost:</strong><br />
AutoRAFi costs $175.00. Since this is a digital product and the source is fully viewable there is no refund. We will work with you to correct any issues. To purchase this please visit our product page: <a href="http://www.digitaloffensive.com/products-page/voip-sip/autorafi-automatic-remote-asterisk-and-freepbx-install/">Products</a></p>
<p><strong>Support:</strong><br />
This script was developed and tested thoroughly on Fedora and CentOS. We ran it over 100x on each OS working out all the flaws.<br />
We provide limited email support for free for this script. We plan to eventually offer a ticket system for this script if it is required. To get support please send a detail email with exact errors (Screen shots) to support@digitaloffensive.com<br />
Free updates of this script will be provided to those that have purchased it.<br />
If you need support configuring FreePBX, or anything else outside of this script and would like our help our hourly rate is $50.00 an hour. Min 2 hours.<br />
Check out http://www.digitaloffensive.com for more info on our services.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.digitaloffensive.com%2F2010%2F10%2Fautorafi-automatic-remote-asterisk-and-freepbx-install-for-fedora-and-centos%2F&amp;title=AutoRAFI%20%28Automatic%20Remote%20Asterisk%20and%20FreePBX%20%20Install%29%20for%20Fedora%20and%20CentOS" id="wpa2a_14"><img src="http://www.digitaloffensive.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.digitaloffensive.com/2010/10/autorafi-automatic-remote-asterisk-and-freepbx-install-for-fedora-and-centos/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Facebook Bot: FBCbot.pl</title>
		<link>http://www.digitaloffensive.com/2010/08/facebook-bot-fbcbot-pl/</link>
		<comments>http://www.digitaloffensive.com/2010/08/facebook-bot-fbcbot-pl/#comments</comments>
		<pubDate>Tue, 31 Aug 2010 16:39:26 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://www.digitaloffensive.com/?p=271</guid>
		<description><![CDATA[Facebook Bot: FBCbot.pl FBCbot is a bot written in Perl to interface with Facebook on the users behalf. The bot is still in its infant stage and could definitely be improved upon. Currently FBCbot was developed on Linux though since it is written in Perl it can be modified to run on Windows as well. [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Facebook Bot: FBCbot.pl</strong></p>
<p>FBCbot is a bot written in Perl to interface with Facebook on the users behalf. The bot is still in its infant stage and could definitely be improved upon. Currently FBCbot was developed on Linux though since it is written in Perl it can be modified to run on Windows as well. The FBCbot was developed in a way to allow for quick writing and adding of additional modules to it. Side note I am pretty new to programming in Perl, so if you see something that could be improved please let me know.</p>
<p><span id="more-271"></span></p>
<p>FBCbot works by checking all your friends status updates for key words that are predefined as commands in the bot. By default FBCbot comes with two modules. The “nmap” module allows users to post the command nmap xxx.xxx.xxx.xxx , where the xxx.xxx.xxx.xxx is the IP to NMAP. Once it is done scanning the IP it will post the results back to the wall of the user that issued the command. The “ping” module allows users to post the command pingpong xxx.xxx.xxx.xxx, where the xxx.xxx.xxx.xxx is the IP to PING. Once it is done pinging the IP it will post the results back to the wall of the user that issued the command.</p>
<p><a href="http://www.digitaloffensive.com/wp-content/uploads/2010/08/nmap.jpg"><img class="aligncenter size-medium wp-image-274" title="nmap" src="http://www.digitaloffensive.com/wp-content/uploads/2010/08/nmap-300x235.jpg" alt="" width="300" height="235" /></a><a href="http://www.digitaloffensive.com/wp-content/uploads/2010/08/pingpong.jpg"><img class="aligncenter size-medium wp-image-275" title="pingpong" src="http://www.digitaloffensive.com/wp-content/uploads/2010/08/pingpong-300x209.jpg" alt="" width="300" height="209" /></a></p>
<p>To use FBCbot you will need to have a Perl interpreter installed on your operating system. I am currently using the default one that comes with Linux. You will need a way to schedule the bot to run, I currently use the cron to have it check every x amount of minutes. You will also need the Facebook command line application that was written by Dave Tompkins over at <a href="http://fbcmd.dtompkins.com/">http://fbcmd.dtompkins.com/</a>. This allows you to send commands via command line to Facebook as well as craft custom Facebook queries like you would do in SQL. Facebook command line runs on both Linux and Windows as well. Once you have this application you will need to overwrite the original fbcmd.php with my modified one. The modified one is provided in the zip along with FBCbot.pl: <a title="http://www.digitaloffensive.com/files/fbcbot.zip" href="http://www.digitaloffensive.com/files/fbcbot.zip" target="_blank">http://www.digitaloffensive.com/files/fbcbot.zip</a></p>
<p>I altered the original fbcmd.php file to add a common delimiter to the “fstatus” output to make separating the username and the command easier since the white space between the username and status is never the same. To do this I added “::” to be printed out right before the actual status</p>
<p>To add additional modules to FBCbot you can use the “elsif” syntax in Perl. Basically you would say</p>
<p>If $command = “x” then do “y” elsif $command =”a” then do “b” and so on. Just make sure to use proper syntax and close everything you open.</p>
<p>The current limitations to FBCbot are that it can only do 10 wall posts day. More than that will have it blocked for 48 hours. I am currently thinking of implementing a way that a user can provide an email address to have the results mailed to but that is a future though if more development is done FBCbot. I also need to take into consideration how to handle people leaving commands in their status over long periods of time.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.digitaloffensive.com%2F2010%2F08%2Ffacebook-bot-fbcbot-pl%2F&amp;title=Facebook%20Bot%3A%20FBCbot.pl" id="wpa2a_16"><img src="http://www.digitaloffensive.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.digitaloffensive.com/2010/08/facebook-bot-fbcbot-pl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AMJchan: Automating the chan_sip.so patching for Magic Jack</title>
		<link>http://www.digitaloffensive.com/2010/07/amjchan-automating-the-chan_sip-so-patching-for-magic-jack/</link>
		<comments>http://www.digitaloffensive.com/2010/07/amjchan-automating-the-chan_sip-so-patching-for-magic-jack/#comments</comments>
		<pubDate>Thu, 29 Jul 2010 18:58:29 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://www.digitaloffensive.com/?p=232</guid>
		<description><![CDATA[AMJchan: Automating the chan_sip.so patching for Magic Jack AMJchan is a shell script written by the Digital Offensive team to quickly and accurately patch your Asterisk server for use with the Magic jack. This script was developed and tested on Centos, fedora and Redhat. The script can be easily altered to use another package manager [...]]]></description>
			<content:encoded><![CDATA[<p>AMJchan: Automating the chan_sip.so patching for Magic Jack</p>
<p>AMJchan is a shell script written by the Digital Offensive team to quickly and accurately patch your Asterisk server for use with the Magic jack. This script was developed and tested on Centos, fedora and Redhat. The script can be easily altered to use another package manager other then yum to make it cross system compliant.</p>
<p><span id="more-232"></span></p>
<p>As many of you already know that to use a Magic Jack in any means other than the intended means  you are required to use a proxy. The Proxy facilitates the md5 hashing of the connection. In most cases people choose to use mjproxy, for Linux, some routers and ATA devices or MJMD5.exe for windows based systems. The actual patch was not developed by us and we cannot take credit for that. From my resources the patch was developed by 2 individuals DTM and Teddy_b. The patch allows you to run your Asterisk PBX without using a proxy.</p>
<p>AMJchan does the following for you:</p>
<ol>
<li>Checks to find out what version of Asterisk you are running</li>
<li>Checks to make sure you have the needed tools (wget and patch)</li>
<li>Installs needed tools if you do not.</li>
<li>Downloads the Asterisk SRC that matches the version you have installed.</li>
<li>Downloads the Magic Jack chan_sip patch code.</li>
<li>Backups your original chan_sip.so and .c files</li>
<li>Patches the chan_sip</li>
<li>Makes the new chan_sip</li>
<li>Stops the asterisk process</li>
<li>Copies the new chan_sip into production</li>
<li>Restarts asterisk</li>
</ol>
<p>To download the script click here: <a href="http://www.digitaloffensive.com/files/amjchan.sh">http://www.digitaloffensive.com/files/AMJchan.sh</a></p>
<p>AMJchan should be run as root to insure that you do not have any permission issues. The Digital Offensive does not take any responsibility for your use of this script.</p>
<p>If you have any questions or feedback please feel free to contact us and if this script helped you feel free to support us through a donation if you see fit.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.digitaloffensive.com%2F2010%2F07%2Famjchan-automating-the-chan_sip-so-patching-for-magic-jack%2F&amp;title=AMJchan%3A%20Automating%20the%20chan_sip.so%20patching%20for%20Magic%20Jack" id="wpa2a_18"><img src="http://www.digitaloffensive.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.digitaloffensive.com/2010/07/amjchan-automating-the-chan_sip-so-patching-for-magic-jack/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Simple Asterisk Auto Dialer</title>
		<link>http://www.digitaloffensive.com/2010/07/simple-asterisk-auto-dialer/</link>
		<comments>http://www.digitaloffensive.com/2010/07/simple-asterisk-auto-dialer/#comments</comments>
		<pubDate>Fri, 09 Jul 2010 18:36:17 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://www.digitaloffensive.com/?p=225</guid>
		<description><![CDATA[Simple Asterisk Auto Dialer What is it: This simple shell script was created by Michael LaSalvia of Digital Offensive to auto dial numbers and plays back a message to the person that picks up the phone. This script will take a comma separated file (CSV) that is setup as follows: Number,Sound,Trunk_Name And automate the dialing [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Simple Asterisk Auto Dialer</strong></p>
<p><strong>What is it:</strong></p>
<p>This simple shell script was created by Michael LaSalvia of Digital Offensive to auto dial numbers and plays back a message to the person that picks up the phone. This script will take a comma separated file (CSV) that is setup as follows:</p>
<p><strong>Number,Sound,Trunk_Name</strong></p>
<p>And automate the dialing and playing of that sound / message. The sound can be in the standard gsm format or an mp3 file.  This is useful for automating phone campaigns or just having a good time messing with friends.</p>
<p><strong>How it works:</strong></p>
<p>This script takes advantage of the Asterisk outgoing spool directory. The script creates a “call” file using the variables that you provided in the csv file as well as the variables you set in the script. The file is then moved into the /var/sppol/asterisk/outgoing directory where asterisk will process the “call” file and place the call.</p>
<p><span id="more-225"></span></p>
<p><strong>The CSV file:</strong></p>
<p>The CSV file is setup with three columns number, sound and trunk_name</p>
<p>The telephone number must not contain any – and must be the full 10 digit number for local and long distance calls. This may vary based on your dial plan.</p>
<p>To play custom sounds / messages you will need to create them and upload them to /var/lib/asterisk/sounds. Make sure that all the files you upload there that you chown them to asterisk.asterisk if your PBX is running as asterisk. When adding the sound to play in the CSV file do not add the extension just define the exact name.</p>
<p>To allow you to use different trunks to place your calls we added a column to define your trunks. If you only have one trunk then use that trunks name on each line</p>
<p>The CSV should look like this:</p>
<p>7175551111,campaign1,trunk1</p>
<p>7174442222,campaingn2,trunk2</p>
<p>And so on….</p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong>The shell script variables:</strong></p>
<p>If you are not sure what you are doing please leave all the settings here along except nFile and nTrunk.</p>
<ol>
<li>sounds: this variable defines the path to the asterisk sounds. You must upload your custom sounds /messages to this directory for them to play.</li>
<li>rOut: this variable defines the path to the asterisk outgoing spool directory.</li>
<li>rUser: this variable defines the user as asterisk.</li>
<li>rGroup: this variable defines the group as asterisk.</li>
<li>nFile: this variable defines the path and file name of your CSV file. You need to upload that file to a readable spot on your PBX.</li>
<li>rtry: this variable defines the max time to wait between trying to call a user back.</li>
<li>mtry: this variable defines the max number of times to try to call someone back.</li>
<li>stime: this variable defines the time to wait before calling the next number. This will help avoid congestion.</li>
</ol>
<p><strong>What is needed:</strong></p>
<ol>
<li>You will need an Asterisk based PBX.
<ol>
<li>You will need to have an account that has the ability to access required directories and files. Preferably root.</li>
<li>You will need to modify the /etc/asterisk/modules.conf file and add the line “load pbx_spool.so”</li>
<li> You will need to have a copy of our script which can be downloaded here: <a href="http://www.digitaloffensive.com/files">http://www.digitaloffensive.com/files</a></li>
<li>You will need a client to upload your sound / message files to the server with as well as your CSV file.</li>
</ol>
</li>
</ol>
<p><strong>How to run:</strong></p>
<p>To run this script you will need to either manually execute it daily or schedule it via cron.</p>
<p><strong>Current issues:</strong></p>
<p>Since I do not have access to the do not call lists database I cannot add the functionality to check your CSV file against the do not call list.<strong> </strong>With that being stated I do not take any responsibility for your actions with this script.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.digitaloffensive.com%2F2010%2F07%2Fsimple-asterisk-auto-dialer%2F&amp;title=Simple%20Asterisk%20Auto%20Dialer" id="wpa2a_20"><img src="http://www.digitaloffensive.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.digitaloffensive.com/2010/07/simple-asterisk-auto-dialer/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>CheckPoint Site to Site VPN Audit automation with “fwm logexport and scripting”</title>
		<link>http://www.digitaloffensive.com/2010/07/checkpoint-site-to-site-vpn-audit-automation-with-%e2%80%9cfwm-logexport-and-scripting%e2%80%9d/</link>
		<comments>http://www.digitaloffensive.com/2010/07/checkpoint-site-to-site-vpn-audit-automation-with-%e2%80%9cfwm-logexport-and-scripting%e2%80%9d/#comments</comments>
		<pubDate>Wed, 07 Jul 2010 13:55:37 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://www.digitaloffensive.com/?p=217</guid>
		<description><![CDATA[CheckPoint Site to Site VPN Audit automation with “fwm logexport and scripting” Up to recently we use to pay a third party SEIM provider to provide us reporting for all our site to site VPN tunnels. This is due to an audit requirement we had that said that our system administrators had to report on [...]]]></description>
			<content:encoded><![CDATA[<p><strong>CheckPoint Site to Site VPN Audit automation with “fwm logexport and scripting”</strong></p>
<p>Up to recently we use to pay a third party SEIM provider to provide us reporting for all our site to site VPN tunnels. This is due to an audit requirement we had that said that our system administrators had to report on any time their vendor connected to the tunnel. If they connected they had to provide the start date &amp; time, the end date &amp; time, the duration of the connection, the source address and destination address, the protocol &amp; port as well as the tunnel name.</p>
<p>Due to the cost of the third party SEIM provider as well as their not so wonderful service we decided to find a replacement. The only issue is the replacements we found all cost over 100,000 a year. This is when Michael Yan and I set forth to develop our own solution.</p>
<p>We are happy to bring you “CP-VPN-Auto-Audit 1.0”. This system is compromised of 4 scripts that run together to export your logs, format them into individual tunnel csv reports and then email them to the system administrators.<br />
<span id="more-217"></span><br />
<strong>To use these scripts you will need the following:</strong></p>
<ol>
<li>You must be running the SPLAT operating system on your management server</li>
<li>You must install active Perl on your mgmt server.</li>
<li>You must have a SSH key pair setup with another Linux box that has the ability to mail files. (This is useful for log backups and automated upgrade_exports as well).</li>
<li>Understanding of basic Perl, Linux and Shell scripting.</li>
<li>You must configure your logs to rotate nightly at midnight and make sure to do a install database to apply the settings.</li>
</ol>
<p><strong>How to install Active Perl on your Mgmt server:</strong></p>
<p>Since the Splat Operating system is just a striped down secured version of Red Hat Linux you are able to install some dependency limited RPM packages.</p>
<ol>
<li>Log into your mgmt server and escalate your privileges to “expert”</li>
<li>Download the RPM that is right for your processor architect: <a href="http://www.activestate.com/activeperl/downloads">http://www.activestate.com/activeperl/downloads</a>. This file needs to be downloaded to a box that has either a SSH server running or an ftp server running since your mgmt station will not have wget, curl or lynx. But you do have SCP and FTP</li>
<li>From your mgmt server copy the RPM over to /root.</li>
<li>Issue the command “rpm –ivh file_name.rpm” to install</li>
<li>Next we will have to edit our environment so the Splat operating system will detect it.
<ol>
<li>Use your favorite Linux editor to edit the file $FWDIR/tmp/.CPprofile.sh</li>
<li>Find the line “PATH=${PATH}:${FWDIR}/bin:” and modify it to PATH=${PATH}:${FWDIR}/bin:/opt/ActivePerl-5.10/bin ; (change to version number that matches your Perl version).</li>
<li>Log out of your mgmt server, log back in and escalate your privilege to “expert”</li>
<li>Execute the command “which perl” You should get a path back if it worked.</li>
</ol>
</li>
</ol>
<p><strong> </strong></p>
<p><strong>Installation of the Perl script on the mgmt server:</strong></p>
<p>On the mgmt server you will need to copy the logstrap.pl and the vpn-audit.pl to the /root directory. Once you have the files copied there you will need to modify them to match your version of checkpoint , the log output directory, the remote server name and account. I normally like to use variables but in this project the use of variables seemed to add so many headaches and countless additional hours of trouble shooting.</p>
<p><strong>Inside look at logstrap.pl:</strong> Download code here: <a href="http://www.digitaloffensive.com/files">http://www.digitaloffensive.com/files</a></p>
<p>The code is heavily documented so to keep this document clean just search for the lines below to see the code:</p>
<p>#Get Yesterday Date:  This code will get the server time and convert it from epoch and format it to a usable format for us. It will also add a 0 in front of any day value that has only 1 character.</p>
<p>#Create shell script to use *CheckPoint Environment* and Process the log export for yesterday log: This code will create the shell script called execute-me.sh. This script will define the CheckPoint environment and process the day before account logs using the fwm logexport command. Next since the cron will spawn a new shell when we declare the CheckPoint environment we need a script that will launch the rest of the code for us in the new shell, this script does that for us by call /root/vpn-audit.pl.</p>
<p><strong>Inside look at vpn-audit.pl:</strong> Download code here: <a href="http://www.digitaloffensive.com/files">http://www.digitaloffensive.com/files</a></p>
<p>The code is heavily documented so to keep this document clean just search for the lines below to see the code:</p>
<p>#Get Yesterday Date:  This code will get the server time and convert it from epoch and format it to a usable format for us. It will also add a 0 in front of any day value that has only 1 character.</p>
<p>#Logs to use: This code will open all the log files that we will use to separate the log file into individual csv files, 1 per vpn tunnel that we have.</p>
<p>#Printing header: This code will add a header to each of the csv files. This allows for easy filtering of results and also makes understanding what data is in each column.</p>
<p># Find Column numbers based on column names since *CheckPoint changes the column numbers daily*: This code will resolve the issue of where the column numbers found in the CheckPoint logs change daily. Instead of using a preset number we find the column name and then find what column that is associated with.</p>
<p>#Process individual reports: This is the part of the code where we process each VPN tunnel into and individual report using regular expression matching and unique tunnel names.</p>
<p>#Close all open logs: This code will close all the logs that we have opened.</p>
<p># Tar files and move them to server to be emailed: This code will make use of the SSH keys we have established with our other Linux box. It will tar up the logs and transfer them to the other box. It will also clean up all the logs we just created as well as call the mail.sh code located on the other box.</p>
<p><strong>Inside look at the crontab entry on the mgmt server:</strong></p>
<p>To edit your crontab use the command “crontab –e”</p>
<p>45 11 * * * /root/logstrap.pl &gt;&amp; /var/log/cron.err</p>
<p>Since we use GMT time I have to set the cron 4 hours in the future from the time I want to execute the script. We output the results to /var/log/cron.err for error checking and debugging.</p>
<p><strong>Installation of mail.sh on your other Linux server:</strong> Download code here: <a href="http://www.digitaloffensive.com/files">http://www.digitaloffensive.com/files</a></p>
<p>Remember on this server you have already confirmed that you can send email from it.</p>
<ol>
<li>Log on to the box as the user that you established the SSH key pair with.</li>
<li>Create a directory called vpn.</li>
<li>Copy the mail.sh code into that directory.</li>
<li>chmod –Rf 777 /user/vpn</li>
</ol>
<p><strong>Inside look at mail.sh:</strong></p>
<p>##Variables: This section will allow you to define the following:</p>
<ol>
<li>The path to the csv files</li>
<li>The mail recipient.</li>
<li>The email message body.</li>
<li>The subject line of the email.</li>
</ol>
<p>## Do not edit below this line: This section of the code contains a loop that will mail all the csv files as attachments until it is done. It will also clean up and remove all the tars and csv files after it sends them out.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.digitaloffensive.com%2F2010%2F07%2Fcheckpoint-site-to-site-vpn-audit-automation-with-%25e2%2580%259cfwm-logexport-and-scripting%25e2%2580%259d%2F&amp;title=CheckPoint%20Site%20to%20Site%20VPN%20Audit%20automation%20with%20%E2%80%9Cfwm%20logexport%20and%20scripting%E2%80%9D" id="wpa2a_22"><img src="http://www.digitaloffensive.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.digitaloffensive.com/2010/07/checkpoint-site-to-site-vpn-audit-automation-with-%e2%80%9cfwm-logexport-and-scripting%e2%80%9d/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Create custom ringtones for Cisco IP Phones</title>
		<link>http://www.digitaloffensive.com/2010/03/create-custom-ringtones-for-cisco-ip-phones/</link>
		<comments>http://www.digitaloffensive.com/2010/03/create-custom-ringtones-for-cisco-ip-phones/#comments</comments>
		<pubDate>Mon, 22 Mar 2010 18:27:56 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://www.digitaloffensive.com/?p=182</guid>
		<description><![CDATA[After months of research of a simple way to create custom ringtones for Cisco IP phones I have come up with the following methods based on the Cisco documentation located at : http://www.cisco.com/en/US/docs/voice_ip_comm/cucm/admin/3_0_9/a3rings.html . Cisco requires that the custom ringtones meet strict guidelines. This baffles me as my cell phone can play full length mp3 [...]]]></description>
			<content:encoded><![CDATA[<p>After months of research of a simple way to create custom ringtones for Cisco IP phones I have come up with the following methods based on the Cisco documentation located at : <a href="http://www.cisco.com/en/US/docs/voice_ip_comm/cucm/admin/3_0_9/a3rings.html" target="_blank">http://www.cisco.com/en/US/docs/voice_ip_comm/cucm/admin/3_0_9/a3rings.html</a> . Cisco requires that the custom ringtones meet strict guidelines. This baffles me as my cell phone can play full length mp3 files as a custom ringtones and costs a fraction of a Cisco IP phone. Oh well I digress. To accomplish this I chose to use the “sox” application. Sox is like a Swiss army knife for sound editing and the best part it is free.</p>
<p>I have created a simple shell script below that will automate the process for you. This script was written to run on the Linux based PBX (Trixbox, PBX in a Flash, Asterisk and so on). Though with a little editing of the script you can use it to just create the ringtones and not install them.</p>
<p><span id="more-182"></span></p>
<ol>
<li>Make sure you have sox installed: which sox and if you don’t you can install it with either apt-get or  yum.</li>
<li>Download the wav files or mp3 that you want to convert to your PBX but. I suggest using Google or another means to find files you want to use. Remember mp3 support may not work.</li>
<li>Copy the code below and paste it into a file on your Linux box using your favorite editor.</li>
<li>Open the shell script and edit the variables if your paths are different. If you don’t know what to put here leave it blank. These are the paths on your PBX where the phone will pull its configurations from.</li>
<li>Save the changes and chmod the file so you can execute it.</li>
<li>Excute the script:</li>
<li>When prompted for the path and name of file you want to convert enter it like this: /music/ring.wav</li>
<li>When prompted for the path and name of the output file it enter it like this: /music/ring (no extension)</li>
<li>Watch for errors and correct where needed.</li>
<li>If you are running this on a Linux PBX it will copy the file to the /tftpboot dir and edit the RINGLIST.DAT file for you.</li>
<li>Once the script is done reboot your phone</li>
</ol>
<p>#!/bin/bash<br />
#####################################<br />
## Create custom cisco ringtones   ##<br />
## Created by Michael LaSalvia     ##<br />
## http://www.digitaloffensive.com ##<br />
## Tested on cisco 7940 and 7960   ##<br />
## Running SIP                       ##<br />
#####################################</p>
<p>#Variables<br />
dtftp=/tftpboot<br />
fring=$dtftp/RINGLIST.DAT</p>
<p>#My current sox install does not support mp3. Most do not by default.<br />
echo &#8220;Enter the path and name of the file you want to convert: &#8221;<br />
read inRing<br />
echo &#8220;Enter the path and name of the output file: &#8221;<br />
read oRing<br />
echo &#8220;#############################################&#8221;<br />
echo &#8220;Converting the file&#8221;<br />
echo &#8220;#############################################&#8221;<br />
#Not all sox installs support -b without a positive integer<br />
sox $inRing -t raw -r 8000 -U -b -c 1 $oRing.raw resample -ql<br />
echo &#8220;#############################################&#8221;<br />
echo &#8220;Resizing the file(16080B) and saving to $dtftp&#8221;<br />
echo &#8220;#############################################&#8221;<br />
dd if=oRing.raw of=$dtftp/$oRing.raw bs=1005 count=16<br />
echo &#8220;#############################################&#8221;<br />
echo &#8220;Editing the RINGLIST&#8221;<br />
echo &#8220;#############################################&#8221;<br />
echo &#8220;$oRing    $oRing.raw&#8221; &gt;&gt; $dtftp/$fring<br />
echo &#8220;#############################################&#8221;<br />
echo &#8220;If there was no errors above, please reset your phone and choose your new ring&#8221;<br />
echo &#8220;#############################################&#8221;</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.digitaloffensive.com%2F2010%2F03%2Fcreate-custom-ringtones-for-cisco-ip-phones%2F&amp;title=Create%20custom%20ringtones%20for%20Cisco%20IP%20Phones" id="wpa2a_24"><img src="http://www.digitaloffensive.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.digitaloffensive.com/2010/03/create-custom-ringtones-for-cisco-ip-phones/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Cpanel remote FTP backup script</title>
		<link>http://www.digitaloffensive.com/2010/02/cpanel-remote-ftp-backup-script/</link>
		<comments>http://www.digitaloffensive.com/2010/02/cpanel-remote-ftp-backup-script/#comments</comments>
		<pubDate>Mon, 22 Feb 2010 15:17:09 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://www.digitaloffensive.com/?p=117</guid>
		<description><![CDATA[Cpanel remote FTP backup script Years ago I did web hosting as a side source of income. This led to me developing  a lot of Linux based scripts to help automate my daily sysadmin responsibilities. Our hosting company was  called ezhostingpro.com. Since then another party owns the domain but googling that and my name will [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><strong><span style="text-decoration: underline;">Cpanel remote FTP backup script</span></strong></p>
<p style="text-align: left;">
Years ago I did web hosting as a side source of income. This led to me developing  a lot of Linux based scripts to help automate my daily sysadmin responsibilities. Our hosting company was  called ezhostingpro.com. Since then another party owns the domain but googling that and my name will lead you to several of my scripts being hosted by other sites. I posting the code on my site as I am finding many people on http://www.getafreelancer.com using codes I post on this site to bid on projects and win them.</p>
<p>This script is in two parts. The first part creates the backup and the second part transfers the backup remotely. The first part of the script makes use of the built in backup commands in cpanel. The script needs minor changes to be used by resellers instead of dedicated server owners.</p>
<p style="text-align: left;"><span style="text-decoration: underline;"><strong>Script 1:</strong></span></p>
<p>#!/bin/bash</p>
<p>############################################<br />
## ##<br />
## EZHOSTINGPRO BACKUP FTP SCRIPT v1.0 ##<br />
## Created by Michael LaSalvia ##<br />
## http://www.digitaloffensive.com ##<br />
## 2/23/04 rev 1 ##<br />
############################################<br />
## 1. Create a file called cpbackup.txt in /root<br />
## 2. Place account names you wanted backup<br />
## 3. Save file in /root<br />
############ DO NOT EDIT BELOW #############<br />
cd /root<br />
for users in $(cat cpbackup.txt)<br />
do<br />
rm -rf /home/$users/cpmove-$users.tar.gz<br />
/scripts/pkgacct $users<br />
mv /home/cpmove-$users.tar.gz /home/$users/<br />
cd /home/$users<br />
chown $users.$users cpmove-$users.tar.gz<br />
chmod 777 cpmove-$users.tar.gz<br />
/home/$users/bkftp.sh<br />
cd /root<br />
done</p>
<p style="text-align: left;"><span style="text-decoration: underline;"><strong>Script 2:</strong></span> This script needs to beedited with the users ftp credentials and placed in the user home dir.</p>
<p>#!/bin/bash</p>
<p>##################################<br />
## EZHOSTINGPRO REMOTE BACKUP ##<br />
## created by: Michael LaSalvia ##<br />
##http://www.digitaloffensive.com##<br />
## DO NOT EDIT THIS FILE ##<br />
## Name this file bkftp.sh chmod 777 ##<br />
##################################</p>
<p>### VARIABLES ###</p>
<p>var_cpaneluser=’cpanel_user_goes_here’<br />
var_remote=’remote_server_goes_here’<br />
var_ftpuser=’remote_server_ftp_username_goes_here’<br />
var_ftppass=’remote_server_ftp_password_goes_here’</p>
<p>cd /home/$var_cpaneluser<br />
ftp -n $var_remote &lt;&lt;END_SCRIPT<br />
quote USER $var_ftpuser<br />
quote PASS $var_ftppass<br />
del cpmove-$var_cpaneluser.tar.gz<br />
put cpmove-$var_cpaneluser.tar.gz<br />
quit<br />
END_SCRIPT<br />
exit 0<br />
rm -Rf cpmove-$var_cpaneluser.tar.gz</p>
<p style="text-align: left;">I believe the newer cpanel system actually provides a built in method to do this, though since I do not have access to one to test I will post this any way. If you have any questions comments or concerns please feel free to contact me.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.digitaloffensive.com%2F2010%2F02%2Fcpanel-remote-ftp-backup-script%2F&amp;title=Cpanel%20remote%20FTP%20backup%20script" id="wpa2a_26"><img src="http://www.digitaloffensive.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.digitaloffensive.com/2010/02/cpanel-remote-ftp-backup-script/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Detecting Malware and other malicious files using md5 hashes</title>
		<link>http://www.digitaloffensive.com/2010/02/detecting-malware-and-other-malicious-files-using-md5-hashes/</link>
		<comments>http://www.digitaloffensive.com/2010/02/detecting-malware-and-other-malicious-files-using-md5-hashes/#comments</comments>
		<pubDate>Sat, 20 Feb 2010 15:57:14 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://www.digitaloffensive.com/?p=111</guid>
		<description><![CDATA[Detecting Malware and other malicious files using md5 hashes The initial interest for this research came to me after reading an article on this on the site http://enclavesecurity.com/ . In the article they talk about using the malicious hashes to discover malware and other malicious files on their systems. They also take a deeper look [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><span style="text-decoration: underline;"><strong>Detecting Malware and other malicious files using md5 hashes</strong></span></p>
<p>The initial interest for this research came to me after reading an article on this on the site <a href="http://enclavesecurity.com/">http://enclavesecurity.com/</a> . In the article they talk about using the malicious hashes to discover malware and other malicious files on their systems. They also take a deeper look into the recent APT and Auroa attacks on Google. Though the thing I found most interesting is trying to develop a way to automate this process for free and provide usable information.</p>
<p>The biggest thing to understand before continuing on is that this is not a fool proof process as a simple change of the file will change the hash of the file. For example if you have the c99.php shell and change the password or add a white space to the php this will change the hash of the file hence making detection via this method impossible. The other issue I have noticed in using this methodology is no one is willing to share all the information. Many companies will only share bits and pieces such as “The Malware Hash Registry” (http://www.team-cymru.org) considered the leading authority on this topic. They make part of their service available online to submit hashes to and get back the following information:</p>
<p>Ex:1: 7697561ccbbdd1661c25c86762117613 1258054790 NO_DATA</p>
<p>Ex:2: cbed16069043a0bf3c92fff9a99cccdc 1231802137 69</p>
<p>In example 1 you see the md5 hash then the epoch date and time then NO_Data meaning it could not tell if this hash is malicious.  In example 2 you see the same except instead of NO_data you see 69. This number means that 69% of the Antivirus vendors they used to check this file with found it to be malicious. This info is good but I find it to be not very helpful. It is nice to know that it was detected as malicious but is it truly malicious and if it is what type of malicious file is it, is it a backdoor, key logger or so on. I have emailed them asking if they could provide the detection type; with understanding that most of their system is private as they will not disclose the database or the vendors they use to scan the files. Though I have not heard back from them at this point.</p>
<p>This led me to searching the internet for other sites like this that provided additional information along with the hash. In this search I found one other site called <a href="http://malwarehash.com/">http://malwarehash.com</a> a sub site of the company <a href="http://www.novirusthanks.org/">NoVirusThanks.org</a>. They provide an online utility to submit your hash to and if it is discovered as malicious it will give you info back. See screen shot below:</p>
<p><a href="http://www.digitaloffensive.com/wp-content/uploads/2010/02/malwarehash.jpg"><img class="alignleft size-thumbnail wp-image-112" title="malwarehash" src="http://www.digitaloffensive.com/wp-content/uploads/2010/02/malwarehash-150x150.jpg" alt="" width="150" height="150" /></a></p>
<p>As you can see they provide an additional layer over what you get from the Malware Hash Registry. On top of that they use a simple PHP script for the query that makes scripting this so much easier:</p>
<p>http://www.malwarehash.com/result.php?hash=1E71DE2D6A89AA9796344BB7FA23AC7E</p>
<p>As you can see in the URL you have the site the script and the hash. The only issue with this site is that it seems they have not updated their database since 6/2009. I have contacted them as well to ask them about this and to see what their plans are for the site though I have not heard back from them either.</p>
<p>With this information in hand I set forth to develop a script that would allow me to automate this process as we have found this methodology to be helpful at work even if it is not 100% accurate as we notice that most malware will not get detected by our Anti virus so by using the hashes and relying on the internet community we are able to help our detection and remediation of malicious files.</p>
<p>To use this script you will need to have a Linux user account and some basic knowledge of Linux to set the variables properly. I wrote the script in bash for two reasons 1 it is a piece of cake to do and 2 so you be forced to move the malicious file off a windows environment where you stand a higher chance of infecting your self.  First access your shell and create a directory called what ever you want but in the code we used a directory called infect that is set in a variable for easy changing. Once you do that copy the malware-hash.sh script to 1 directory above the folder you just created. Then copy the sed script file to a file called clean in the directory that you created. Once you have done this chmod the malware-hash.sh script so you can execute it and chmod the clean script so the malware-hash.sh script can read it. Once done all you have to do now is copy the suspicious files to the directory you created and execute the script. The script will get a listing of all the files in that folder, remove the clean script, and any dupes from the listing and then get the md5 hash of each file. Once it gets the hashes it will create a batch file to be processed against The Malware Hash Registry and save the results in a clean human readable format. We use the batch function to stay with in the TOS of the site.  This includes adding the file names in front of the hash so you know what the hash belongs to. Next it will take the hashes and run them through the site Malwarehash.com. We use the &#8211;random-wait command with wget here to not act like a bot or script. If it gets a hit for a infection we will grab the site and scrape out the data we want then process it into a human readable report. Once all done we will combine the results of both checks and email the final results to the email address provided.</p>
<p><span id="more-111"></span></p>
<p>The script is written in bash and is highly documented:</p>
<p>The script is broken down into 2 sections the actual script and the sed script file.</p>
<p><span style="text-decoration: underline;"><strong>Part 1 the Script:</strong></span> Copy this script to a file with a .sh extension or download it here <a href="http://www.digitaloffensive.com/malware-hash.sh" target="_blank">http://www.digitaloffensive.com/malware-hash.sh</a> . I suggest downloading it as the word press system will definitely destroy the formatting of the code. Place this script 1 directory up from the directory that you are using for the infected files.</p>
<p>#!/bin/bash<br />
################################################<br />
## MALWARE HASH BASH                           ##<br />
## Written by Michael LaSalvia                  ##<br />
## http://www.digitaloffensive.com              ##<br />
## Inspired by an article at enclave Security ##<br />
################################################</p>
<p>#Variables and clean up<br />
#Edit in Path to dir that contains file for analysis<br />
inPath=/home/mike/virus/infect</p>
<p>#Path to your md5sum app to verify it is not compromised. I got the hash from a new install on fedora 12.<br />
wmd5sum=/usr/bin/md5sum</p>
<p>md5sum /usr/bin/md5sum &gt; .tmp<br />
mverify=`cut -f 1 -d &#8216; &#8216; .tmp`<br />
if [$mverify == 019329f334fa7ef6116ad1a24271c8da ] then<br />
echo &#8220;Your md5 hash matches&#8221;<br />
else<br />
echo &#8221; Your md5sum hash is not right, Please verify it before continuing. Press CTRL+C now to exit&#8221;<br />
fi<br />
rm -Rf .tmp<br />
# I strongly urge you to make sure your md5 application is not compromised or the rest of this script is useless.<br />
Sleep 20</p>
<p>#Get a list of file to analyze and get their hash<br />
ls $inPath &gt; files.txt<br />
for vfiles in $(cat files.txt)<br />
do<br />
cd $inPath<br />
md5sum $vfiles &gt;&gt; hashes<br />
sort hashes | uniq &gt; $inPath/hashes.txt<br />
done<br />
#Clean up my files<br />
cat $inPath/hashes.txt | grep -v hashes &gt;&gt; .tmp; mv .tmp $inPath/hashes.txt<br />
cat $inPath/hashes.txt | grep -v md5 &gt;&gt; .tmp; mv .tmp $inPath/hashes.txt<br />
cat $inPath/hashes.txt | grep -v clean &gt;&gt; .tmp; mv .tmp $inPath/hashes.txt</p>
<p>#Format file to submit to http://www.team-cymru.org as a batch<br />
cut -f 1 -d &#8216; &#8216; $inPath/hashes.txt &gt;&gt; $inPath/md5hash.txt<br />
cut -f 3 -d &#8216; &#8216; $inPath/hashes.txt &gt;&gt; $inPath/md5name.txt<br />
echo &#8220;begin&#8221;| cat &#8211; $inPath/md5hash.txt &gt; .tmp &amp;&amp; mv .tmp $inPath/md5hash.txt<br />
echo end &gt;&gt; $inPath/md5hash.txt<br />
rm -Rf $inPath/hashes.txt</p>
<p>#Send batch request o the Malware Hash Registry (I Love netcat)<br />
nc hash.cymru.com 43 &lt; $inPath/md5hash.txt &gt; $inPath/md5results.txt</p>
<p>#Clean up response and format it<br />
cat $inPath/md5results.txt | grep -v &#8220;#&#8221; &gt;&gt; .bk; mv .bk $inPath/md5results.txt<br />
paste $inPath/md5name.txt $inPath/md5results.txt &gt; $inPath/results.txt<br />
#cat $inPath/results.txt<br />
cat $inPath/md5hash.txt | grep -v &#8220;begin&#8221; &gt;&gt; .tmp; mv .tmp $inPath/md5hash.txt<br />
cat $inPath/md5hash.txt | grep -v &#8220;end&#8221; &gt;&gt; .tmp; mv .tmp $inPath/md5hash.txt</p>
<p>#Dirty web scraper and formating (site may be out of date)<br />
for whashes in $(cat $inPath/md5hash.txt)<br />
do<br />
wget &#8211;random-wait http://www.malwarehash.com/result.php?hash=$whashes -O $whashes<br />
if grep &#8220;INFECTED&#8221; $whashes &gt; /dev/null; then<br />
cat $whashes | grep -m 1 a-squared &gt;&gt; $inPath/.tmp<br />
cat $whashes | grep -m 1 &#8220;Avira AntiVir&#8221; &gt;&gt; $inPath/.tmp<br />
cat $whashes | grep -m 1 &#8220;Avast&lt;&#8221; &gt;&gt; $inPath/.tmp<br />
cat $whashes | grep -m 1 AVG &gt;&gt; $inPath/.tmp<br />
cat $whashes | grep -m 1 BitDefender &gt;&gt; $inPath/.tmp<br />
cat $whashes | grep -m 1 ClamAV &gt;&gt; $inPath/.tmp<br />
cat $whashes | grep -m 1 Comodo &gt;&gt; $inPath/.tmp<br />
cat $whashes | grep -m 1 &#8220;Dr.Web&#8221; &gt;&gt; $inPath/.tmp<br />
cat $whashes | grep -m 1 Ewido &gt;&gt; $inPath/.tmp<br />
cat $whashes | grep -m 1 F-PROT &gt;&gt; $inPath/.tmp<br />
cat $whashes | grep -m 1 &#8220;G DATA&#8221; &gt;&gt; $inPath/.tmp<br />
cat $whashes | grep -m 1 IkarusT3 &gt;&gt; $inPath/.tmp<br />
cat $whashes | grep -m 1 Kaspersky &gt;&gt; $inPath/.tmp<br />
cat $whashes | grep -m 1 McAfee &gt;&gt; $inPath/.tmp<br />
cat $whashes | grep -m 1 &#8220;Malware Hash Registry&#8221; &gt;&gt; $inPath/.tmp<br />
cat $whashes | grep -m 1 NOD32 &gt;&gt; $inPath/.tmp<br />
cat $whashes | grep -m 1 Norman &gt;&gt; $inPath/.tmp<br />
cat $whashes | grep -m 1 Panda &gt;&gt; $inPath/.tmp<br />
cat $whashes | grep -m 1 &#8220;QuickHeal&#8221; &gt;&gt; $inPath/.tmp<br />
cat $whashes | grep -m 1 &#8220;Solo Antivirus&#8221; &gt;&gt; $inPath/.tmp<br />
cat $whashes | grep -m 1 Sophos &gt;&gt; $inPath/.tmp<br />
cat $whashes | grep -m 1 TrendMicro &gt;&gt; $inPath/.tmp<br />
cat $whashes | grep -m 1 VBA32 &gt;&gt; $inPath/.tmp<br />
cat $whashes | grep -m 1 &#8220;VirusBuster&#8221; &gt;&gt; $inPath/.tmp<br />
#More Cleaning and report creation.<br />
sed -f $inPath/clean $inPath/.tmp &gt; $inPath/.tmp1; mv $inPath/.tmp1 $inPath/$whashes<br />
rm -Rf .tmp .tmp1<br />
echo &#8220;Results from MalwareHash.com&#8221; &gt;&gt; $inPath/final_report.txt<br />
echo &#8221; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8221; &gt;&gt; $inPath/final_report.txt<br />
echo &#8220;$whashes : &#8221; &gt;&gt; $inPath/final_report.txt<br />
echo &#8221; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8221; &gt;&gt; $inPath/final_report.txt<br />
cat $inPath/$whashes &gt;&gt; $inPath/final_report.txt<br />
echo &#8221; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8221; &gt;&gt; $inPath/final_report.txt<br />
else<br />
echo &#8220;Results from MalwareHash.com&#8221; &gt;&gt; $inPath/final_report.txt<br />
echo &#8220;NO RESULTS FOUND for: $whashes&#8221; &gt;&gt; $inPath/final_report.txt<br />
echo &#8221; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8221; &gt;&gt; $inPath/final_report.txt<br />
fi<br />
rm -Rf $inPath/$whashes<br />
rm -Rf $inPath/md5*<br />
rm -Rf $inPath/hashes<br />
done<br />
cat $inPath/results.txt | cat &#8211; $inPath/final_report.txt &gt; .tmp &amp;&amp; mv .tmp $inPath/final_report.txt<br />
echo &#8220;Results from The Malware Hash Registry&#8221; | cat &#8211; $inPath/final_report.txt &gt; .tmp &amp;&amp; mv .tmp $inPath/final_report.txt<br />
mail -s&#8221;Malware&#8221; me@me.com &lt; final_report.txt</p>
<p><strong><span style="text-decoration: underline;">Part 2 the sed script:</span></strong></p>
<p>Copy this code and put it in a file called clean located in the folder that has the files you want to analyze and chmod it so the script can read it.</p>
<p>s/&lt;tr&gt;&lt;th&gt;/AV Name:/<br />
s/&lt;tr&gt;&lt;th width=&#8221;150&#8243;&gt;/AV Name:/<br />
s/&lt;\/th&gt;&lt;td width=&#8221;83&#8243;&gt;/ Sig Version:/<br />
s/&lt;\/td&gt;&lt;td width=&#8221;100&#8243;&gt;/ Engine Version:/<br />
s/&lt;\/td&gt;&lt;td width=&#8221;116&#8243;&gt;/ Engine Version:/<br />
s/&lt;\/th&gt; &lt;td width=&#8221;83&#8243;&gt;/ Sig Version:/<br />
s/&lt;\/td&gt; &lt;td width=&#8221;116&#8243;&gt;/ Engine Version:/<br />
s/&lt;\/t&lt;td width=&#8221;213&#8243;&gt;&lt;font color=&#8221;#336600&#8243; size=&#8221;3&#8243;&gt;-/ Virus Name: Nothing Found/<br />
s/&lt;\/t&lt;td width=&#8221;213&#8243;&gt;&lt;font color=&#8221;#336600&#8243; size=&#8221;3&#8243;&gt;-/ Virus Name: Nothing Found/<br />
s/&lt;\/td&gt;&lt;td width=&#8221;213&#8243;&gt; &lt;font color=&#8221;#336600&#8243; size=&#8221;3&#8243;&gt;-/ Virus Name: Nothing Found/<br />
s/&lt;\/td&gt;&lt;td width=&#8221;213&#8243;&gt; &lt;font color=&#8221;#CC0000&#8243; size=&#8221;2&#8243;&gt;/ Virus Name: /<br />
s/&lt;\/td&gt;&lt;td width=&#8221;213&#8243;&gt;&lt;font color=&#8221;#CC0000&#8243; size=&#8221;2&#8243;&gt;/ Virus Name: /<br />
s/&lt;\/td&gt;&lt;td width=&#8221;190&#8243;&gt; &lt;font color=&#8221;#CC0000&#8243; size=&#8221;2&#8243;&gt;/ Virus Name: /<br />
s/&lt;\/td&gt; &lt;td width=&#8221;213&#8243;&gt; &lt;font color=&#8221;#336600&#8243; size=&#8221;3&#8243;&gt;-/ Virus Name: Nothing Found/<br />
s/&lt;\/td&gt; &lt;td width=&#8221;213&#8243;&gt; &lt;font color=&#8221;#CC0000&#8243; size=&#8221;2&#8243;&gt;/ Virus Name: /<br />
s/&lt;\/font&gt;&lt;\/td&gt;&lt;//<br />
s/\/tr&gt;//<br />
s/&lt;\/font&gt;&lt;\/t//<br />
s/&lt;\/font&gt; &lt;//<br />
s/&lt;\/font&gt;&lt;\/td&gt; &lt;\/tr//<br />
s/&gt; &lt;\/tr//<br />
s/d&gt;//</p>
<p>Though this methodology is a few years old there is many things that can be done with this. For example we are in the process of writing a tripwire type script that will allow web masters to monitor changes to their sites and to be able to quickly see what was added or modified as well as run it though the process above to search for infections / compromise</p>
<p>As always if you have any questions, comments or concerns please feel free to contact me.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.digitaloffensive.com%2F2010%2F02%2Fdetecting-malware-and-other-malicious-files-using-md5-hashes%2F&amp;title=Detecting%20Malware%20and%20other%20malicious%20files%20using%20md5%20hashes" id="wpa2a_28"><img src="http://www.digitaloffensive.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.digitaloffensive.com/2010/02/detecting-malware-and-other-malicious-files-using-md5-hashes/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Google Calculator Scraper</title>
		<link>http://www.digitaloffensive.com/2010/01/google-calculator-scraper/</link>
		<comments>http://www.digitaloffensive.com/2010/01/google-calculator-scraper/#comments</comments>
		<pubDate>Fri, 15 Jan 2010 19:07:08 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://www.digitaloffensive.com/?p=97</guid>
		<description><![CDATA[Recently I was reading an article about using Ruby on Rails to create a web scraper as I sat there and learned Ruby I got really excited to jump to the point and build a web scraper. Though as any programmer knows that is not possible until you have the base understanding of the language [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I was reading an article about using Ruby on Rails to create a web scraper as I sat there and learned Ruby I got really excited to jump to the point and build a web scraper. Though as any programmer knows that is not possible until you have the base understanding of the language down. So to solve my dilemma I set forth to try to write one via a shell script.<br />
I was not sure what I wanted to scrap so after a few hours of thinking I decided to basically make a calculator using Google’s calculator feature.  Basically a user will be able to do basic arithmetic for any two numbers and get the answer via Google. If you want to try this manually go to Google and type 1+2 and hit enter. It is that simple, well close to that simple.<br />
To start off I ran several different manual tests to see what the URL should look like depending on the operator I used. I found out that all operators acted like they should accept addition the “+” gets converted to “%2B” this proposed a small issue but nothing that a little extra scripting could not resolve.<br />
To get around this and to make the program interactive for the user I did this:</p>
<blockquote><p>#!/bin/bash<br />
#######################################<br />
## Simple Google Query and web scraper<br />
## Written by Michael LaSalvia<br />
## http://www.digitaloffensive.com<br />
## Created: 1/15/09<br />
#######################################<br />
##Variables<br />
tFile=gmath.txt<br />
oFile=rmath.txt<br />
rm $tFile<br />
echo &#8220;If there was a error above this line that is ok&#8221;<br />
echo &#8220;###################################&#8221;<br />
echo &#8220;# Press (a) for addition          #&#8221;<br />
echo &#8220;# Press (s) for subtraction       #&#8221;<br />
echo &#8220;# Press (m) for multiplication    #&#8221;<br />
echo &#8220;# Press (d) for division          #&#8221;<br />
echo &#8220;###################################&#8221;</p>
<p>echo -e &#8220;What do you want to do:&#8221;<br />
read Mmath<br />
case $Mmath in<br />
&#8220;a&#8221;) dMath=%2B &amp;&amp; echo &#8220;You chose addition&#8221;;;<br />
&#8220;s&#8221;) dMath=- &amp;&amp; echo &#8220;You chose subtration&#8221;;;<br />
&#8220;m&#8221;) dMath=* &amp;&amp; echo &#8220;You chose multiplication&#8221;;;<br />
&#8220;d&#8221;) dMath=/ &amp;&amp; echo &#8220;You chose divsion&#8221;;;<br />
esac</p></blockquote>
<p>Now that we know what arithmetic the end user wants to do we need to find out what variables they want to use. To do this we do this:</p>
<blockquote><p>echo -e &#8220;Enter first number:&#8221;<br />
read nNum1<br />
echo -e &#8220;Enter Second number:&#8221;<br />
read nNum2</p></blockquote>
<p>Now that we have all the needed variables comes the fun part. We now need to construct the URL, but since it is Google and they do not allow automated responses we need to make our script look like a real user agent as well. (<span style="color: #ff0000;"><strong>WARNING: </strong></span>This may break Google’s AUP). To do this we used the following code:</p>
<blockquote><p>wget &#8211;header=&#8221;User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)&#8221; &#8220;http://www.google.com/search?hl=en&amp;safe=off&amp;q=$nNum1$dMath$nNum2&#8243; -q -O $tFile</p></blockquote>
<p>The user agent we chose to masquerade as was Internet Explorer 8. You will also notice that we outputted the file to a “known” file. This makes the rest of the process much easier and simpler to code.<br />
Now that we have the full page downloaded we need to find just the information we want. To do this I first manually reviewed the source code of the page and notice that no matter what math problem I entered the source code always had the following around each problem EX.</p>
<p>Code: style=&#8221;font-size: 138%;&#8221;&gt;&lt;b&gt;999 + 998 = 1&lt;font size=&#8221;-2&#8243;&gt; &lt;/font&gt;997&lt;/b&gt;</p>
<p>So to remove everything except what I wanted I used the following code:</p>
<blockquote><p>cat $tFile | awk -F &#8220;138%\&#8221;&gt;&lt;b&gt;&#8221; {&#8216;print $2&#8242;} | awk -F &#8220;&lt;/b&gt;&#8221; {&#8216;print $1&#8242;} &gt; $oFile<br />
echo &#8220;Your answer is:&#8221; &amp;&amp; cat $oFile</p></blockquote>
<p>You will notice that I did not clean the file fully, that is because I noticed that when it was echoed to the terminal the html that was left did not show and instead of sitting there using “sed” to fully clean it up I left it as is.<br />
I hope you have learned something from this. If you have any questions or concerns please feel free to contact me.</p>
<p>Here is a screen shot:</p>
<p><a href="http://www.digitaloffensive.com/wp-content/uploads/2010/01/math.jpg" target="_blank"><img class="alignleft size-medium wp-image-100" title="math" src="http://www.digitaloffensive.com/wp-content/uploads/2010/01/math-232x300.jpg" alt="" width="139" height="180" /></a></p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.digitaloffensive.com%2F2010%2F01%2Fgoogle-calculator-scraper%2F&amp;title=Google%20Calculator%20Scraper" id="wpa2a_30"><img src="http://www.digitaloffensive.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.digitaloffensive.com/2010/01/google-calculator-scraper/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP SMS Sender</title>
		<link>http://www.digitaloffensive.com/2009/10/php-sms-sender/</link>
		<comments>http://www.digitaloffensive.com/2009/10/php-sms-sender/#comments</comments>
		<pubDate>Thu, 22 Oct 2009 01:24:14 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://www.digitaloffensive.com/?p=81</guid>
		<description><![CDATA[Simple SMS sender It is no secret that almost all the cell phone companies today allow you to send txt messages to a person’s cell phone for free by means of emailing them a txt. This does not mean the company will not charge the receiver but the sender will not be charged.  To do [...]]]></description>
			<content:encoded><![CDATA[<p>Simple SMS sender</p>
<p>It is no secret that almost all the cell phone companies today allow you to send txt messages to a person’s cell phone for free by means of emailing them a txt. This does not mean the company will not charge the receiver but the sender will not be charged.  To do this all you need is a email client or a web mail client and the following information:</p>
<p>T-Mobile: <em>phonenumber</em>@tmomail.net<br />
Virgin Mobile: <em>phonenumber</em>@vmobl.com<br />
Cingular: <em>phonenumber</em>@cingularme.com<br />
Sprint: <em>phonenumber</em>@messaging.sprintpcs.com<br />
Verizon: <em>phonenumber</em>@vtext.com<br />
Nextel: <em>phonenumber</em>@messaging.nextel.com</p>
<p>For example if I want to txt 717-555-1234 and that user is a Verizon user you would simply put <a href="mailto:7175551234@vtext.com">7175551234@vtext.com</a> in the “To” field and enter a small message in the body. Remember most cell phones are limited to 160 characters and cannot handle all the crazy things a standard email can.</p>
<p>Though an enough on this as you are here to learn about the code and a simple Google and can provide you with more information on the above topic.</p>
<p>Since I rarely try to PHP program I decided to write a PHP e-mailer that basically gave the user the ability to use a web form to send a SMS message to someone through an email.</p>
<p><img class="aligncenter size-full wp-image-82" title="sms" src="http://www.digitaloffensive.com/wp-content/uploads/2009/10/sms.jpg" alt="sms" /></p>
<p>The URL above will no longer work I removed the file so spammers and script kiddies could not use it.</p>
<p>To follow a long you need to have basic knowledge of PHP and HTML. If you do then this will be simple for you.  To view the code you can download it by click here <a href="http://www.digitaloffensive.com/mailer.txt" target="_blank">http://www.digitaloffensive.com/mailer.txt</a></p>
<p><strong>Section 1: </strong>This contains the author’s information as well as a warning about using the script as it is not written securely. This section also contains the die command to stop scrip kiddies from using file include and leaching off the script.</p>
<p><strong>Section 2:</strong> Is the actual PHP code this is where I define the variables by using $variableName = $_POST[‘textboxName’]. I use the POST command instead of the GET command as POST is used for tasks that will be done in the background and not displayed to the end user in the URL. In this section I also put basic logic check functionality in. Basically by using “if isset” I am able to define a field to make sure something is inserted before executing the code. If I did not have this in their every time the page loaded it would try to send and fail since no fields are defined by default. The final key element of this section is the “mail” command this is a PHP built in command and will use the “sendmail” application to send mail.</p>
<p><strong>Section 3:</strong> This section contains the actual code to make the form. This is the entire html that makes the text boxes and submit button. The key elements here are the names I used for the text box in the “id=”  or in the “name=” field as they tie in directly with the variables in the PHP section.</p>
<p>That covers all the code if you have any questions please feel free to post a comment and I will answer them. I plan to develop security in this app as I sharpen my skills of the PHP language past just searching for vulnerabilities.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.digitaloffensive.com%2F2009%2F10%2Fphp-sms-sender%2F&amp;title=PHP%20SMS%20Sender" id="wpa2a_32"><img src="http://www.digitaloffensive.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.digitaloffensive.com/2009/10/php-sms-sender/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>c99 and variant PHP shell detection, quarantine and removal</title>
		<link>http://www.digitaloffensive.com/2009/10/c99-and-variant-php-shell-detection-quarantine-and-removal/</link>
		<comments>http://www.digitaloffensive.com/2009/10/c99-and-variant-php-shell-detection-quarantine-and-removal/#comments</comments>
		<pubDate>Thu, 08 Oct 2009 18:52:58 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://www.digitaloffensive.com/?p=76</guid>
		<description><![CDATA[c99 and variant PHP shell detection, quarantine and removal Every day I review my web server’s visitor stats and logs and the other day I noticed something odd. I saw a URL that was accessed 35 times from the same exact IP and I did not recognize the file as being a part of Word [...]]]></description>
			<content:encoded><![CDATA[<p><strong>c99 and variant PHP shell detection, quarantine and removal</strong></p>
<p>Every day I review my web server’s visitor stats and logs and the other day I noticed something odd. I saw a URL that was accessed 35 times from the same exact IP and I did not recognize the file as being a part of Word Press or any static page I have uploaded.  The file was called Photo13.php. While investigating this file I noticed several files with the time stamp of the night before. These new files were a part of the breach. In total there was three files found. The c99 PHP shell and two other scripts 1 was used to drop webmail.exe on to a visitor’s machine and the other was to email passwords from webmail users to the owner.</p>
<p>Before you all jump on me about Word Press and its security flaws let me assure you I try to make sure to keep the core up to date every time there is an available update. I believe the breach was either on the host side, a weak cPanel password of one of my client sites or the twitter plug-in on the Word Press site.  I am personally leading more on the twitter plug-in or the hosts as these sites have been hosted for over two years on another host with the same configurations and there was not an issue until recently. Also today there was an important upgrade warning about the twitter plug-in.</p>
<p>This got me thinking how I can be sure to have removed all copies of c99 PHP shell and its variants that the attacker might have installed and how I can take a more active approach in detecting this shell and others. When I copied the c99 PHP shell to my local machine and viewed the code I noticed that it is encoded in base 64 as many of you already know that. When you decode this you get a compressed file it is not until you decompress the file you can see the actual code. If you are interested in decoding this file I suggest using Google to search for “gzinflate base64_decode”. Though it was encrypted I did notice that the coding was the same for several c99 PHP shells that I found on other peoples sites via Google.</p>
<p>With this information I decided I could reliably detect a potentially infected file by running it through three separate string checks. So I wrote the following shell script: To download the code in a .sh file <a title="http://www.digitaloffensive.com/c99fix.sh" href="http://www.digitaloffensive.com/c99fix.sh" target="_blank">click here</a> (Word Press messes up the formatting.)</p>
<blockquote><p>#/bin/bash<br />
##################################################################<br />
### c99 and variant shell detection, quarantine and or removal ###<br />
### Created by: Michael LaSalvia on 10/08/09                   ###<br />
### Site: http://www.digitaloffensive.com                      ###<br />
### Not responsible for your use of this script                ###<br />
##################################################################<br />
#Variables: if you dont know what you are doing leave these as is<br />
txtInfect=/tmp/php.txt<br />
dirSearch=/var/www/<br />
qInfected=/tmp/infected<br />
ck1=/tmp/c99check1.txt<br />
ck2=/tmp/c99check2.txt<br />
ck3=/tmp/c99check3.txt</p>
<p>echo &#8220;########################################################&#8221;<br />
echo &#8220;## Creating needed files and cleaning old check files ##&#8221;<br />
echo &#8220;## Ignore errors here                                 ##&#8221;<br />
echo &#8220;########################################################&#8221;<br />
mkdir $qInfected<br />
rm -f $ck1 $ck2 $ck3 $txtInfect</p>
<p>echo &#8220;########################################################&#8221;<br />
echo &#8220;### STARTING SEARCH FOR c99 and vairants            ####&#8221;<br />
echo &#8220;########################################################&#8221;</p>
<p>find $dirSearch -name \*.php &gt;&gt; $txtInfect<br />
for c99 in $(cat $txtInfect)<br />
do<br />
if grep &#8220;gzinflate&#8221; $c99 &gt; /dev/null; then<br />
echo &#8220;$c99 is infected **CHECK 1 of 3**&#8221;<br />
echo $c99 &gt;&gt; $ck1<br />
for c992 in $(cat $ck1)<br />
do<br />
if grep &#8220;&#8217;7X1rcxs5kuBnd0T&#8221; $c992 &gt; /dev/null; then<br />
echo &#8220;$c992 is infected **CHECK 2 of 3**&#8221;<br />
echo $c992 &gt;&gt; $ck2<br />
for c993 in $(cat $ck2)<br />
do<br />
if grep &#8220;/wxMNVWOra7tTSb4BOrTD7FuM+847ZoXbxU7K2m2Elzg1RYWkhKujJiJa6QaqTwy9X5tCDZ6f77AUoj9XtkXuWQ5ROgowOYpU59wydY/&#8221; $c993 &gt; /dev/null; then<br />
echo &#8220;$c993 is infected **CHECK 3 of 3**&#8221;<br />
echo $c993 &gt;&gt; $ck3<br />
echo -e &#8220;##############################################################&#8221;<br />
echo -e &#8220;## After 3x c99 code has been found in the following files: ##&#8221;<br />
cat $ck3.txt<br />
echo -e &#8220;##############################################################&#8221;<br />
echo -e &#8220;#####  Press 1: To delete these files **WARNING**        #####&#8221;<br />
echo -e &#8220;#####  Press enter: Rename the infected php to .txt      #####&#8221;<br />
echo -e &#8220;#####  and move it to $qInfected for review           #####&#8221;<br />
echo -e &#8220;##############################################################&#8221;<br />
echo -e &#8220;Please enter your choice:    &#8221;<br />
read yChoice<br />
if [ "$yChoice" == 1 ]<br />
then<br />
for rmInfect in $(cat $ck3)<br />
do<br />
rm -f $rmInfect<br />
echo &#8220;** $rmInfect has been removed&#8221;<br />
done<br />
else<br />
for mvRname in $(cat $ck3)<br />
do<br />
mv $mvRname $mvRname.txt<br />
mv $mvRname.txt $qInfected<br />
echo &#8220;$mvRname has been renamed to $mvRname.txt&#8221;<br />
echo $mvRname.txt has been moved to $qInfected<br />
done<br />
fi<br />
fi<br />
done<br />
fi<br />
done<br />
fi<br />
done<br />
rm -f $ck1 $ck2 $ck3 $txtInfect</p></blockquote>
<p>The shell script is based on my worm detection shell script, which can be found here: <a title="http://www.digitaloffensive.com/2009/10/removing-a-mass-web-site-infection/" href="http://www.digitaloffensive.com/2009/10/removing-a-mass-web-site-infection/" target="_blank">http://www.digitaloffensive.com/2009/10/removing-a-mass-web-site-infection/</a>. This script basically searches the “PATH” you provide it for all the files on your system with a .php extension and saves them to a file. The script then checks each file that is the list using three nested “for loops”. The first for loop checks for the string “gzinflate” as that is not a common command in most web scripts. If the string is detected it logs the file and path to another file, if there is no possible infection it will end the script. If the string was found the next for loop will search the possible infected files for the string “&#8217;7X1rcxs5kuBnd0T” Once again if the string is found it will copy the file path and name to another file and if nothing is detected it will end the script. The last for loop searches for the string “/wxMNVWOra7tTSb4BOrTD7FuM+847ZoXbxU7K2m2Elzg1RYWkhKujJiJa6QaqTwy9X5tCDZ6f77AUoj9XtkXuWQ5ROgowOYpU59wydY/”. If this string is detected it saves the file path and name to another file. You are then prompted to take action against the script. You will have the option to enter “1” to remove all the infected files that were found or you can just press any other key (enter) and it will rename the file to give it a .txt extension so the attacker cannot execute it, it will also move the file to a quarantined folder in your /tmp directory for your review.</p>
<p>If you have any questions, comments or concerns please feel free to post them or contact me.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.digitaloffensive.com%2F2009%2F10%2Fc99-and-variant-php-shell-detection-quarantine-and-removal%2F&amp;title=c99%20and%20variant%20PHP%20shell%20detection%2C%20quarantine%20and%20removal" id="wpa2a_34"><img src="http://www.digitaloffensive.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.digitaloffensive.com/2009/10/c99-and-variant-php-shell-detection-quarantine-and-removal/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Removing a mass web site infection</title>
		<link>http://www.digitaloffensive.com/2009/10/removing-a-mass-web-site-infection/</link>
		<comments>http://www.digitaloffensive.com/2009/10/removing-a-mass-web-site-infection/#comments</comments>
		<pubDate>Mon, 05 Oct 2009 17:16:01 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://www.digitaloffensive.com/?p=73</guid>
		<description><![CDATA[Years ago I was big into web hosting and was constantly offering my services to hosts to correct security issues and clean up other issues. One day I found a post where a hosting company had every .php .html .htm and so on page infected with malicious code through a security breach. After finding and [...]]]></description>
			<content:encoded><![CDATA[<p>Years ago I was big into web hosting and was constantly offering my services to hosts to correct security issues and clean up other issues. One day I found a post where a hosting company had every .php .html .htm and so on page infected with malicious code through a security breach. After finding and securing the original breach I wrote this peace of code to go through the system finding all web based files that contained the infectious code and removed it from the pages.  I am now publishing the code on my site for others to use: (<strong><span style="color: #ff0000;">WARNING</span></strong> I would not just copy and use this code without some knowledge and backing up your system. Some tweaks may be needed to help you with your issue.)</p>
<blockquote><p>CODE:</p>
<p>#!/bin/sh<br />
&gt; .tmp<br />
find /home/ -name \*.php &gt;&gt; php.txt<br />
find /home/ -name \*.html &gt;&gt; php.txt<br />
find /home -name \*.htm &gt;&gt; php.txt<br />
for infected in $(cat php.txt)<br />
do<br />
if grep &#8220;http://www.domainstat.net/stat.php&#8221; $infected &gt; /dev/null; then<br />
echo &#8220;$infected is infected now cleaning&#8221;<br />
sed -f clean $infected &gt; .tmp ; mv .tmp $infected<br />
echo &#8220;$infected cleaned&#8221;<br />
else<br />
echo &#8220;$infected is not infected: moving on&#8221;<br />
fi<br />
done<br />
&gt; php.txt</p>
<p>The below code is the clean script that I reference:<br />
s/&lt; ? echo &#8220;&lt;script language=&#8217;JavaScript&#8217; type=&#8217;text\/javascript&#8217; src=&#8217;http:\/\/www.domainstat.net\/stat.php&#8217;&gt;&lt; \/script&gt;&#8221;; ?&gt;//<br />
s/&lt;script language=&#8217;JavaScript&#8217; type=&#8217;text\/javascript&#8217; src=&#8217;http:\/\/www.domainstat.net\/stat.php&#8217;&gt;&lt; \/script&gt;//</p></blockquote>
<p>The code above is a shell script written to search /home (this was written for a cpanel server, most Linux servers store web files in /var/www/html) for files that have common web extensions.  Once it lists all the files into a file called php.txt it then greps through each file looking for the infectious code. If it finds the code it copies the page to a tmp file, uses sed to remove the infectious code and then renames the tmp file back to the original.</p>
<p>If  you have any questions or concerns please feel free to post a comment.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.digitaloffensive.com%2F2009%2F10%2Fremoving-a-mass-web-site-infection%2F&amp;title=Removing%20a%20mass%20web%20site%20infection" id="wpa2a_36"><img src="http://www.digitaloffensive.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.digitaloffensive.com/2009/10/removing-a-mass-web-site-infection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Instant IDS v1.0</title>
		<link>http://www.digitaloffensive.com/2009/09/instant-ids-v1-0/</link>
		<comments>http://www.digitaloffensive.com/2009/09/instant-ids-v1-0/#comments</comments>
		<pubDate>Wed, 23 Sep 2009 14:00:32 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://digitaloffensive.com/?p=28</guid>
		<description><![CDATA[Instant IDS v1.0 Instant IDS v1.0 is a custom shell script that will automatically download, configure and run Snort IDS and BASE web gui. Though this script has been tested in-depth I the author do not guarantee it will work and or not harm your system. Since this is a shell script and can be [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Instant IDS v1.0</strong></p>
<p>Instant IDS v1.0 is a custom shell script that will automatically download, configure and run Snort IDS and BASE web gui.</p>
<p>Though this script has been tested in-depth I the author do not guarantee it will work and or not harm your system. Since this is a shell script and can be easily edited I strongly suggest that you don’t download it from any site but http://www.digitaloffensive.com. Please note that IDS systems need to configure to properly work in your environment. Until they are tuned you may receive false positives.</p>
<p>This script has been tested in-depth on CentOS 5.0, Fedora Core 7 and Fedora Core 6. This script should work on any other Linux flavor that makes use of yum and chkconfig.</p>
<p>This script currently makes use of the snort 2.7 and the rules that were released with this version. We do not download new rules for you as Snort requires a user account to download newer rules. We strongly suggest that if you like the Snort product that you subscribe to their subscription rule base service to receive new rules faster.</p>
<p><strong>What is needed?</strong></p>
<p>a)      A default install of Linux with gcc (no need to choose http, mysql or anything like that)</p>
<p>b)      A Internet Connection<br />
<strong><br />
What Does Instant IDS provide you?</strong></p>
<p>Instant IDS provides you with a fully functional IDS system in minutes. The script will download all needed services, libraries and packages that are needed. It will install and configure each of these items based on the underlying operating system. It will also configure and start the needed services based on user input. Once done it provides you with a fully working IDS system running Snort, MySql and BASE.</p>
<p><strong>What are we planning to do in the future?</strong></p>
<p>Since 96% of the script pulls the newest packages using yum we plan to make sure that we keep the script up to date as new versions of Snort, Base and Libpcap are released. We plan to make the script more customizable by introducing the ability to configure variables. We plan to add more advance means of error checking and improve the code. We also plan to have it lock down the box as much as possible based on user input. With all this said we rely on the users of the script to tell us what they like and don’t like and what they would like us to do in future releases.<br />
<strong><br />
How to use Instant IDS</strong></p>
<p>a)      cd /root</p>
<p>b)      wget http://www.digitaloffensive.com/snort/snort.sh</p>
<p>c)       chmod 777 snort.sh</p>
<p>d)      ./snort.sh</p>
<p>e)      Answer the questions that you are prompted with. Please make sure that if you are using a subnet that you enter it as xxx.xxx.xxx.xxx\\/24 ß or whatever class it is.</p>
<p>f)       The wait value you enter will give you some time to make sure there is no show stopping errors, some warning are ok. This is only to be used if there is a major issue and a library or application does not install or compile. If you see a major issue press ctrl +c to cancel the rest of the install.</p>
<p>g)      Once instant IDS is installed we suggest you lock down your machine, here are a few examples:</p>
<p>a.       Firewall the machine.</p>
<p>b.      Disable root ssh access.</p>
<p>c.       Create a mysql root password.</p>
<p>d.      Update the systems patches</p>
<p>e.      Disable unneeded services.</p>
<p>This script is released freely we ask that you keep the original authors information in it though you have right to modify the script as you see necessary. This script may not be sold.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.digitaloffensive.com%2F2009%2F09%2Finstant-ids-v1-0%2F&amp;title=Instant%20IDS%20v1.0" id="wpa2a_38"><img src="http://www.digitaloffensive.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.digitaloffensive.com/2009/09/instant-ids-v1-0/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Null Session Scanning</title>
		<link>http://www.digitaloffensive.com/2009/09/null-session-scanning/</link>
		<comments>http://www.digitaloffensive.com/2009/09/null-session-scanning/#comments</comments>
		<pubDate>Wed, 23 Sep 2009 13:59:12 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://digitaloffensive.com/?p=26</guid>
		<description><![CDATA[Null Session Scanning For a recent audit I was tasked with checking a class C network for null sessions. The task itself sounds simple doesn’t it? But I am not one to just run a quick scan without verifying my work. This caused a interesting discovery. My first run at the network I used NTscan [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Null Session Scanning </strong></p>
<p>For a recent audit I was tasked with checking a class C network for null sessions. The task itself sounds simple doesn’t it? But I am not one to just run a quick scan without verifying my work. This caused a interesting discovery. My first run at the network I used NTscan and discovered 1 machine with a null session open. If this would of been correct then the client would of definitely improved their security posture since the last audit they had from another company. To verify my work I then ran xscan v3, though I prefer their older versions I could not find a working clean copy in the short time frame I had to use it. This scan returned 3 open machines. Now this was odd but I chalked it up to maybe another machine came up in the time frame it took to run the tools. The third scan I ran with a tool called netscan and this tool not only returned 16 machines open but returned all the drive information with their permissions. Now this totally baffled me, so I ran all three tools one after another and the same results came up. I also manually checked the machines that returned results and each one was indeed open. Now with this in mind I figured the only safest way to confirm what was truly open was to manual test the full class C using net commands. So to this I wrote a simple shell script for CYGWIN to verify the machine was up then to check it for null sessions. The script returned 26 null sessions, which I verified a sampling of them and confirmed my results. The script is attached. The script was not written with the ability to quickly change it with variables as I needed it quickly and did not have time to make it look real pretty. If you would like to customize the script please feel free to do it, or if you need help please feel free to ask.</p>
<p>Part 1:</p>
<p>Verify the node is up: ShareScan: <a title="http://genxweb.net/wp-content/uploads/2007/06/shareup.zip" href="http://genxweb.net/wp-content/uploads/2007/06/shareup.zip" target="_blank">http://genxweb.net/wp-content/uploads/2007/06/shareup.zip</a></p>
<p>This script will go through a txt file and verify that the ips inside the file are up and if they are up moves it to another file that will be used by the scanner to check for null sessions.</p>
<p>Part 2:</p>
<p>Check for null session: Scan Share: <a title="http://genxweb.net/wp-content/uploads/2007/06/scanshare.zip" href="http://genxweb.net/wp-content/uploads/2007/06/scanshare.zip" target="_blank">http://genxweb.net/wp-content/uploads/2007/06/scanshare.zip</a></p>
<p>This script takes the IP addresses that are up from the results from the first part of the script and runs the net use commands on them checking for null sessions. Error checking is basic as we use a simple truth statement &amp;&amp; to say if it was mapped successfully then disconnect it.</p>
<p>Side note: I first published this article on my old site http://www.genxweb.net</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.digitaloffensive.com%2F2009%2F09%2Fnull-session-scanning%2F&amp;title=Null%20Session%20Scanning" id="wpa2a_40"><img src="http://www.digitaloffensive.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.digitaloffensive.com/2009/09/null-session-scanning/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PayPal Garage Sale Point of Sale system</title>
		<link>http://www.digitaloffensive.com/2009/09/paypal-garage-sale-point-of-sale-system/</link>
		<comments>http://www.digitaloffensive.com/2009/09/paypal-garage-sale-point-of-sale-system/#comments</comments>
		<pubDate>Wed, 23 Sep 2009 13:57:19 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://digitaloffensive.com/?p=23</guid>
		<description><![CDATA[PayPal Garage Sale Point of Sale system So I am about to have a garage sale and want to accept credit cards so people can&#8217;t say they don&#8217;t have money so I search all over the internet and there is nothing in the form of a POS for paypal users. So what do I do [...]]]></description>
			<content:encoded><![CDATA[<p><strong>PayPal Garage Sale Point of Sale system</strong></p>
<p>So I am about to have a garage sale and want to accept credit cards so people can&#8217;t say they don&#8217;t have money so I search all over the internet and there is nothing in the form of a POS for paypal users. So what do I do I create a down and dirty one using a simple Batch file.</p>
<p>Check out the code below.</p>
<p>Title Yard Sale Pyapal Check Out<br />
@echo off<br />
cls<br />
set /p ItemNo=Item No:<br />
set /p ItemName=Item Name:<br />
set /p Price=Price:<br />
pause</p>
<p>echo ^&lt;form target=&#8221;paypal&#8221; action=&#8221;https://www.paypal.com/cgi-bin/webscr&#8221; method=&#8221;post&#8221;^&gt;&gt;Out.htm<br />
echo ^&lt;input type=&#8221;hidden&#8221; name=&#8221;cmd&#8221; value=&#8221;_xclick&#8221;^&gt;^&lt;input type=&#8221;hidden&#8221; name=&#8221;amount&#8221; value=&#8221;%Price%&#8221;^&gt;&gt;&gt;Out.htm<br />
echo ^&lt;input type=&#8221;hidden&#8221; name=&#8221;business&#8221; value=&#8221; you@your.comThis e-mail address is being protected from spam bots, you need JavaScript enabled to view it &#8220;^&gt;&gt;&gt;Ou<br />
t.htm<br />
echo ^&lt;input type=&#8221;hidden&#8221; name=&#8221;item_name&#8221; value=&#8221;%ItemName%&#8221;^&gt;&gt;&gt;Out.htm<br />
echo ^&lt;input type=&#8221;hidden&#8221; name=&#8221;item_number&#8221; value=&#8221;%ItemNo%&#8221;^&gt;&gt;&gt;Out.htm<br />
echo ^&lt;input type=&#8221;hidden&#8221; name=&#8221;return&#8221; value=&#8221;www.divepa.com/thanks.html&#8221;^&gt;&gt;&gt;Out.htm<br />
echo ^&lt;input type=&#8221;hidden&#8221; name=&#8221;cbt&#8221; value=&#8221;Continue&#8221;^&gt;&gt;&gt;Out.htm<br />
echo ^&lt;input type=&#8221;image&#8221; src=&#8221;cart.jpeg&#8221; border=&#8221;0&#8243; name=&#8221;submit&#8221; alt=&#8221;button&#8221;^&gt;^&lt;/form^&gt;&gt;&gt;Out.htm<br />
echo ^&lt;br^&gt;^&lt;br^&gt; &gt;&gt;out.htm<br />
echo You are purchasing item: %ItemName% for %Price% if you agree click the cart above and complete your transaction &gt;&gt;out.htm</p>
<p>pause<br />
start /max &#8220;C:\Program Files\Internet Explorer\iexplore.exe&#8221; Out.htm</p>
<p>All you do is copy the above code into a notepad file and save the file as paypal.cmd then double click it and fill in the blanks. Make sure you change the email field first to your paypal email account.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.digitaloffensive.com%2F2009%2F09%2Fpaypal-garage-sale-point-of-sale-system%2F&amp;title=PayPal%20Garage%20Sale%20Point%20of%20Sale%20system" id="wpa2a_42"><img src="http://www.digitaloffensive.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.digitaloffensive.com/2009/09/paypal-garage-sale-point-of-sale-system/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

