<?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>Pario TechnoBlob &#187; nmap</title>
	<atom:link href="http://pario.no/tag/nmap/feed/" rel="self" type="application/rss+xml" />
	<link>http://pario.no</link>
	<description>A cronological documentation test project, nothing serious, really!</description>
	<lastBuildDate>Thu, 02 Feb 2012 13:17:58 +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>Allow NFS through iptables</title>
		<link>http://pario.no/2007/12/20/allow-nfs-through-iptables/</link>
		<comments>http://pario.no/2007/12/20/allow-nfs-through-iptables/#comments</comments>
		<pubDate>Thu, 20 Dec 2007 09:50:41 +0000</pubDate>
		<dc:creator>Hans-Henry Jakobsen</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Network]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[awk]]></category>
		<category><![CDATA[iptables]]></category>
		<category><![CDATA[nmap]]></category>
		<category><![CDATA[rpcinfo]]></category>
		<category><![CDATA[sort]]></category>

		<guid isPermaLink="false">http://pario.no/2007/12/20/allow-nfs-through-iptables/</guid>
		<description><![CDATA[This is one way to determine the ports needed to open in your iptables rules to get NFS to work properly. First we need to determine the ports NFS uses rpcinfo -p &#124; awk -F " " '{print $3 ", " $4 ", " $5}' &#124; sort &#124; uniq Notice! Since portmap assigns ports on [...]]]></description>
			<content:encoded><![CDATA[<p>This is one way to determine the ports needed to open in your iptables rules to get NFS to work properly. First we need to determine the ports NFS uses</p>
<pre>
rpcinfo -p | awk -F " " '{print $3 ", " $4 ", " $5}' | sort | uniq</pre>
<p><strong>Notice!</strong><br />
Since portmap assigns ports on random this example is only valid as long as you don&#8217;t restart your NFS.</p>
<p>On my system, a RedHat Enterprise Linux WS 4, the result was</p>
<pre>
proto, port,
tcp, 111, portmapper
tcp, 2049, nfs
tcp, 32771, nlockmgr
tcp, 768, rquotad
tcp, 782, mountd
udp, 111, portmapper
udp, 2049, nfs
udp, 32768, nlockmgr
udp, 765, rquotad
udp, 779, mountd</pre>
<p>This gave me  a nice overview of protocols (tcp/udp) and ports used.</p>
<p>Now the rules</p>
<pre>
iptables -A RH-Firewall-1-INPUT -s 192.168.0.0/255.255.255.0 -i eth0 -p tcp -m state --state NEW -m multiport --dports 111,2049,32771,768,782 -j ACCEPT
iptables -A RH-Firewall-1-INPUT -s 192.168.0.0/255.255.255.0 -i eth0 -p udp -m state --state NEW -m multiport --dports 111,2049,32768,765,779 -j ACCEPT</pre>
<p>You see that the multiport statement is just like the result of my rpcinfo command above.</p>
<p>Remember to save your new rules, othervise they will disappear the next time the iptables rules are being loaded.</p>
<p>In addition to this rule you should add the <a href="http://pario.no/2007/05/08/ssh-dictionary-attack-prevention-with-iptables/">iptables rule for ssh access</a> I wrote about earlier.</p>
<p>Another way to determine the ports</p>
<pre>
nmap -sC -p 111 localhost</pre>
<p><strong>Notice!</strong><br />
This solution won&#8217;t work after a reboot of the server since NFS changes ports. One way to overcome this problem is to follow the instructions in a newer post I&#8217;ve made about <a href="http://pario.no/2008/01/15/allow-nfs-through-iptables-on-a-redhat-system/">RedHat and NFS</a>.</p>
<script type="text/javascript">var wordpress_toolbar_urls = [];var wordpress_toolbar_url = "http://pario.no/wp-content/plugins/wordpress-toolbar/toolbar.php";var wordpress_toolbar_oinw = "n";var wordpress_toolbar_hash = "aHR0cDovL3BhcmlvLm5vLzIwMDcvMTIvMjAvYWxsb3ctbmZzLXRocm91Z2gtaXB0YWJsZXMvPHdwdGI%2BQWxsb3cgTkZTIHRocm91Z2ggaXB0YWJsZXM8d3B0Yj5odHRwOi8vcGFyaW8ubm88d3B0Yj5QYXJpbyBUZWNobm9CbG9i";</script>]]></content:encoded>
			<wfw:commentRss>http://pario.no/2007/12/20/allow-nfs-through-iptables/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>nmap scanning and printers</title>
		<link>http://pario.no/2007/10/15/nmap-scanning-and-printers/</link>
		<comments>http://pario.no/2007/10/15/nmap-scanning-and-printers/#comments</comments>
		<pubDate>Mon, 15 Oct 2007 12:09:13 +0000</pubDate>
		<dc:creator>Hans-Henry Jakobsen</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Network]]></category>
		<category><![CDATA[nmap]]></category>

		<guid isPermaLink="false">http://pario.no/2007/10/15/nmap-printers/</guid>
		<description><![CDATA[When you plan to nmap scan a network which contains printers, avoid scanning the JetDirect port, port 9100. Newer versions of nmap skips TCP port 9100 because some printers simply print anything sent to that port, leading to dozens of pages of HTTP get requests, binary SSL session requests, etc. This behavior can be changed [...]]]></description>
			<content:encoded><![CDATA[<p>When you plan to nmap scan a network which contains printers, avoid scanning the JetDirect port, port 9100.</p>
<p>Newer versions of nmap skips TCP port 9100 because some printers simply print anything sent to that port, leading to dozens of pages of HTTP get requests, binary SSL session requests, etc. This behavior can be changed by modifying or removing the Exclude directive in nmap-service-probes, or you can specify &#8211;allports to scan all ports regardless of any Exclude directive.</p>
<script type="text/javascript">var wordpress_toolbar_urls = [];var wordpress_toolbar_url = "http://pario.no/wp-content/plugins/wordpress-toolbar/toolbar.php";var wordpress_toolbar_oinw = "n";var wordpress_toolbar_hash = "aHR0cDovL3BhcmlvLm5vLzIwMDcvMTAvMTUvbm1hcC1zY2FubmluZy1hbmQtcHJpbnRlcnMvPHdwdGI%2Bbm1hcCBzY2FubmluZyBhbmQgcHJpbnRlcnM8d3B0Yj5odHRwOi8vcGFyaW8ubm88d3B0Yj5QYXJpbyBUZWNobm9CbG9i";</script>]]></content:encoded>
			<wfw:commentRss>http://pario.no/2007/10/15/nmap-scanning-and-printers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Detecting changes to your network services/damons</title>
		<link>http://pario.no/2007/04/30/detecting-changes-to-your-network-servicesdamons/</link>
		<comments>http://pario.no/2007/04/30/detecting-changes-to-your-network-servicesdamons/#comments</comments>
		<pubDate>Mon, 30 Apr 2007 10:30:23 +0000</pubDate>
		<dc:creator>Hans-Henry Jakobsen</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[basename]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[diff]]></category>
		<category><![CDATA[grep]]></category>
		<category><![CDATA[nmap]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[ping]]></category>

		<guid isPermaLink="false">http://hhj.no/wordpress/2007/04/30/detecting-changes-to-your-network-servicesdamons/</guid>
		<description><![CDATA[This is a tutorial to detect changes in port from hosts on your network. The basic approach is to ping every available address upon your subnet and see which ones are up by detecting replies. If you install the package libperl-net-ping you can use the following script to see which hosts upon your LAN are [...]]]></description>
			<content:encoded><![CDATA[<p>This is a tutorial to detect changes in port from hosts on your network.<br />
The basic approach is to ping every available address upon your subnet and see which ones are up by detecting replies.</p>
<p>If you install the package libperl-net-ping you can use the following script to see which hosts upon your LAN are alive:</p>
<pre>
#!/usr/bin/perl -w

use strict;
use Net::Ping;

my $LAN = "192.168.1.";

foreach my $octet (1 .. 255)
{
	my $pinger = Net::Ping-&gt;new();
	if ( $pinger-&gt;ping( $LAN . $octet ) )
	{
		print  $LAN . $octet . "\n";
	}
	$pinger-&gt;close();
}</pre>
<p>Save the script as /usr/local/bin/scan-lan and make sure it&#8217;s executable by running chmod 755 /usr/local/bin/scan-lan.</p>
<p>This would give you a list of IP addresses which might look like the following:</p>
<pre>
192.168.1.1
192.168.1.2
192.168.1.10
192.168.1.50
192.168.1.90</pre>
<p>With a list like that saved to text file you can now start scanning your network for services.</p>
<p>In order to detect changes to our network we wish to record all the services on the machines in our LAN then later rescan to detect anything different.</p>
<p>Using the scan-lan and nmap we can create a file for each machine that&#8217;s up containing its services.</p>
<p>Save this script as /usr/local/bin/make-baseline, and make it executable with &#8220;chmod 755 /usr/local/bin/make-baseline&#8221;:</p>
<pre>
#!/bin/sh

mkdir -p /var/log/scans

for i in `/usr/local/bin/scan-lan` ; do
    nmap -sV $i | grep ' open ' &gt; /var/log/scans/$i.base
done</pre>
<p>This is our baseline scan. With this in hand we have a list of all the hosts upon a lan which are currently up, and the services they are running.</p>
<p>Now we just to write another script to compare the current state to that we recorded in our baseline, this will notify us of changes.</p>
<p>The following script can do that job for us, save it as /usr/local/bin/scan-services:</p>
<pre>
#!/bin/sh

if [ ! -d /var/log/scans ]; then
   echo "Baseline directory isn't present"
   exit
fi

#
#  Scan all the machines
#
for i in `/usr/local/bin/scan-lan` ; do
    nmap -sV $i | grep ' open ' &gt; /var/log/scans/$i.log
done

#
# Cleanup
#
rm /var/log/scans/*-added.txt
rm /var/log/scans/*-removed.txt
cd /var/log/scans/

#
# Find new and removed
#
for i in /var/log/scans/*.log; do
  diff --context $i ${i/.log/}.base | grep '^+ ' &gt; `basename $i .log`-added.txt
  diff --context $i ${i/.log/}.base | grep '^- ' &gt; `basename $i .log`-removed.txt
done

#
#  Now show the results
#
for i in /var/log/scans/*-added.txt; do
    if [ -s $i ]; then
      echo " "
      echo "The machine `basename $i -added.txt` has had the following services added:"
      cat $i
      echo " "
    fi
done

for i in /var/log/scans/*-removed.txt; do
    if [ -s $i ]; then
      echo " "
      echo "The machine `basename $i -removed.txt` has had the following services removed:"
      cat $i
      echo " "
    fi
done</pre>
<p>If you make this executable and run it you should see no output, as your current network hasn&#8217;t changed in the past few minutes.</p>
<p>Delete a line or two from one or more of the .base files in the /var/log/scans directory and run it again.</p>
<p>This time you should see output like this:</p>
<pre>
The machine 192.168.1.1 has had the following services added:
+ 8889/tcp open  http        GNUMP3d streaming server 2.9

The machine 127.0.0.1 has had the following services removed:
- 19/tcp   open  discard?</pre>
<script type="text/javascript">var wordpress_toolbar_urls = [];var wordpress_toolbar_url = "http://pario.no/wp-content/plugins/wordpress-toolbar/toolbar.php";var wordpress_toolbar_oinw = "n";var wordpress_toolbar_hash = "aHR0cDovL3BhcmlvLm5vLzIwMDcvMDQvMzAvZGV0ZWN0aW5nLWNoYW5nZXMtdG8teW91ci1uZXR3b3JrLXNlcnZpY2VzZGFtb25zLzx3cHRiPkRldGVjdGluZyBjaGFuZ2VzIHRvIHlvdXIgbmV0d29yayBzZXJ2aWNlcy9kYW1vbnM8d3B0Yj5odHRwOi8vcGFyaW8ubm88d3B0Yj5QYXJpbyBUZWNobm9CbG9i";</script>]]></content:encoded>
			<wfw:commentRss>http://pario.no/2007/04/30/detecting-changes-to-your-network-servicesdamons/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Generate a list of target hosts to nmap scan</title>
		<link>http://pario.no/2007/04/26/generate-a-list-of-target-hosts-to-nmap-scan/</link>
		<comments>http://pario.no/2007/04/26/generate-a-list-of-target-hosts-to-nmap-scan/#comments</comments>
		<pubDate>Thu, 26 Apr 2007 08:21:18 +0000</pubDate>
		<dc:creator>Hans-Henry Jakobsen</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[cut]]></category>
		<category><![CDATA[grep]]></category>
		<category><![CDATA[nmap]]></category>

		<guid isPermaLink="false">http://hhj.no/wordpress/2007/04/26/generate-a-list-of-target-hosts-to-nmap-scan/</guid>
		<description><![CDATA[Legg følgende inn i fila iplist.sh #!/bin/bash # filename: iplist.sh # usage: ./iplist.sh 192.168.1.0/24 &#62; iplist.txt nmap -sL $1 --randomize_hosts &#124; grep '^Host' &#124; cut -d '(' -f 2 &#124; cut -d ')' -f 1 Output 192.168.1.215 192.168.1.39 192.168.1.168 192.168.1.11 192.168.1.225]]></description>
			<content:encoded><![CDATA[<p>Legg følgende inn i fila <strong>iplist.sh</strong></p>
<pre>
#!/bin/bash
# filename: iplist.sh
# usage: ./iplist.sh 192.168.1.0/24 &gt; iplist.txt

nmap -sL $1 --randomize_hosts | grep '^Host' | cut -d '(' -f 2 | cut -d
')' -f 1</pre>
<p><span id="more-133"></span><br />
Output</p>
<pre>
192.168.1.215
192.168.1.39
192.168.1.168
192.168.1.11
192.168.1.225</pre>
<script type="text/javascript">var wordpress_toolbar_urls = [];var wordpress_toolbar_url = "http://pario.no/wp-content/plugins/wordpress-toolbar/toolbar.php";var wordpress_toolbar_oinw = "n";var wordpress_toolbar_hash = "aHR0cDovL3BhcmlvLm5vLzIwMDcvMDQvMjYvZ2VuZXJhdGUtYS1saXN0LW9mLXRhcmdldC1ob3N0cy10by1ubWFwLXNjYW4vPHdwdGI%2BR2VuZXJhdGUgYSBsaXN0IG9mIHRhcmdldCBob3N0cyB0byBubWFwIHNjYW48d3B0Yj5odHRwOi8vcGFyaW8ubm88d3B0Yj5QYXJpbyBUZWNobm9CbG9i";</script>]]></content:encoded>
			<wfw:commentRss>http://pario.no/2007/04/26/generate-a-list-of-target-hosts-to-nmap-scan/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>nmap/nbtscan scan for å finne pc med åpen port</title>
		<link>http://pario.no/2007/04/18/nmapnbtscan-scan-for-a-finne-pc-med-apen-port/</link>
		<comments>http://pario.no/2007/04/18/nmapnbtscan-scan-for-a-finne-pc-med-apen-port/#comments</comments>
		<pubDate>Wed, 18 Apr 2007 09:22:31 +0000</pubDate>
		<dc:creator>Hans-Henry Jakobsen</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[awk]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[grep]]></category>
		<category><![CDATA[nbtscan]]></category>
		<category><![CDATA[nmap]]></category>

		<guid isPermaLink="false">http://hhj.no/wordpress/2007/04/18/nmapnbtscan-scan-for-a-finne-pc-med-apen-port/</guid>
		<description><![CDATA[Dette scriptet scanner IP-er fra ei fil og finner ut hvem som har en spesiell port åpen. Lim inn følgende script kode i fila portLookup.sh #!/bin/bash NETWORKTARGET=$1 PORT=$2 FN="port" # Scan Network Input File for active hosts saving IPS to $FNips.txt nmap -sS -p $PORT -n -iL $NETWORKTARGET -oG - &#124; grep open &#124; awk [...]]]></description>
			<content:encoded><![CDATA[<p>Dette scriptet scanner IP-er fra ei fil og finner ut hvem som har en spesiell port åpen.</p>
<p>Lim inn følgende script kode i fila <strong>portLookup.sh</strong></p>
<pre>
#!/bin/bash
NETWORKTARGET=$1
PORT=$2
FN="port"

# Scan Network Input File for active hosts saving IPS to $FNips.txt
nmap -sS -p $PORT -n -iL $NETWORKTARGET -oG - | grep open | awk '/[1-9].[1-9]/ {print $2}' &gt; ${FN}ips.txt

# use nbtscan to find hostnames and generate the ip to name $FNlookup file
nbtscan -f ${FN}ips.txt | awk '/[1-9].[1-9]/ {print $1 " " $2}' &gt; ${FN}lookup.txt

echo "Scan Complete"
echo "Port Scanned: "$PORT
NUMIPS=`cat ${FN}ips.txt | wc -l`
NUMHOSTS=`cat ${FN}lookup.txt | wc -l`
echo "Number of IPs Found: "$NUMIPS " See file ${FN}ips.txt"
echo "Number of Netbios Names Found: "$NUMHOSTS " See file ${FN}lookup.txt"</pre>
<p>Scriptet henter data/IP-adresser fra ei tekstfil og du angir hvilken port som skal scannes pÃ¥ fÃ¸lgende mÃ¥te:</p>
<pre>portLookup.sh tekstfil portnr
portLookup.sh hosts.txt 80</pre>
<p>Eksemplet ovenfor henter ut IP-adresser fra fila hosts.txt og scanner etter PCer med port 80 Ã¥pen.</p>
<p>En enkel mÃ¥te Ã¥ generere ei slik fil kan leses pÃ¥ <a href="http://pario.no/wordpress/2007/04/26/generate-a-list-of-target-hosts-to-nmap-scan/" title="generate-a-list-of-target-hosts-to-nmap-scan">generate a list of target hosts to nmap scan/</a></p>
<p>Resultatet legges i filene <strong>portips.txt</strong> og <strong>portlookup.txt</strong></p>
<script type="text/javascript">var wordpress_toolbar_urls = [];var wordpress_toolbar_url = "http://pario.no/wp-content/plugins/wordpress-toolbar/toolbar.php";var wordpress_toolbar_oinw = "n";var wordpress_toolbar_hash = "aHR0cDovL3BhcmlvLm5vLzIwMDcvMDQvMTgvbm1hcG5idHNjYW4tc2Nhbi1mb3ItYS1maW5uZS1wYy1tZWQtYXBlbi1wb3J0Lzx3cHRiPm5tYXAvbmJ0c2NhbiBzY2FuIGZvciDDpSBmaW5uZSBwYyBtZWQgw6VwZW4gcG9ydDx3cHRiPmh0dHA6Ly9wYXJpby5ubzx3cHRiPlBhcmlvIFRlY2hub0Jsb2I%3D";</script>]]></content:encoded>
			<wfw:commentRss>http://pario.no/2007/04/18/nmapnbtscan-scan-for-a-finne-pc-med-apen-port/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

