|
Registered Member
Join Date: Nov 2004
Posts: 9
|
Parsing ns1 files in PHP - Opensource
Hi,
Obviously, some people want to display the ns1 files from netstumbler on the internet... (enhancing my webstumbler script (Link on netstumbler forums) )
So I'm trying to create a script to do this.
I'm working on it but still have some problems.
This is the script :
PHP Code:
<?php
$jump=0;
function dwSignature($s,$offset)
//4 dwSignature char[4] File Signature ('NetS')
{
global $jump;
$jump=$jump+4;
return substr($s,$offset,4);
}
function dwFileVer($s,$offset)
//4 dwFileVer uint32 File Format Version
{
global $jump;
$jump=$jump+4;
return hexdec(bin2hex($s[0+$offset]))+255*hexdec(bin2hex($s[1+$offset]))+255*255*hexdec(bin2hex($s[2+$offset]))+255*255*255*hexdec(bin2hex($s[3+$offset]));
}
function ApCount($s,$offset)
//4 ApCount uint32 Number of APINFO entries that follow
{
global $jump;
$jump=$jump+4;
return hexdec(bin2hex($s[0+$offset]))+255*hexdec(bin2hex($s[1+$offset]))+255*255*hexdec(bin2hex($s[2+$offset]))+255*255*255*hexdec(bin2hex($s[3+$offset]));
}
function SSIDLength($s,$offset)
//1 SSIDLength uint8 Length of SSID
{
global $jump;
$jump=$jump+1;
return hexdec(bin2hex($s[$offset]));
}
function SSID($s,$length,$offset)
//SSIDLength SSID char[] SSID (SSIDLength characters, no terminating null)
{
global $jump;
$jump=$jump+$length;
return substr($s,$offset,$length);
}
function BSSID($s, $offset)
//6 BSSID uint8[6] BSSID
{
global $jump;
$jump=$jump+6;
return hexdec(bin2hex($s[0+$offset]))&":"&hexdec(bin2hex($s[1+$offset]))&":"&hexdec(bin2hex($s[2+$offset]))&":"&hexdec(bin2hex($s[3+$offset]))&":"&hexdec(bin2hex($s[4+$offset]))&":"&hexdec(bin2hex($s[5+$offset]));
}
function MaxSignal($s, $offset)
//4 MaxSignal int32 Maximum reported signal level, dBm
{
global $jump;
$jump=$jump+4;
return hexdec(bin2hex($s[0+$offset]))+255*hexdec(bin2hex($s[1+$offset]))+255*255*hexdec(bin2hex($s[2+$offset]))+255*255*255*hexdec(bin2hex($s[3+$offset]));
}
function MinNoise($s,$offset)
// 4 MinNoise int32 Minimum reported noise level, dBm
{
global $jump;
$jump=$jump+4;
return hexdec(bin2hex($s[0+$offset]))+255*hexdec(bin2hex($s[1+$offset]))+255*255*hexdec(bin2hex($s[2+$offset]))+255*255*255*hexdec(bin2hex($s[3+$offset]));
}
function MaxSNR($s,$offset)
// 4 MaxSNR int32 Maximum reported signal-to-noise ratio, dB
{
global $jump;
$jump=$jump+4;
return hexdec(bin2hex($s[0+$offset]))+255*hexdec(bin2hex($s[1+$offset]))+255*255*hexdec(bin2hex($s[2+$offset]))+255*255*255*hexdec(bin2hex($s[3+$offset]));
}
function Flags($s,$offset)
// 4 Flags uint32 802.11 capability flags
{
global $jump;
$jump=$jump+4;
return hexdec(bin2hex($s[0+$offset]))+255*hexdec(bin2hex($s[1+$offset]))+255*255*hexdec(bin2hex($s[2+$offset]))+255*255*255*hexdec(bin2hex($s[3+$offset]));
}
function BeaconInterval ($s,$offset)
// 4 BeaconInterval uint32 Beacon Interval, Kµs
{
global $jump;
$jump=$jump+4;
return hexdec(bin2hex($s[0+$offset]))+255*hexdec(bin2hex($s[1+$offset]))+255*255*hexdec(bin2hex($s[2+$offset]))+255*255*255*hexdec(bin2hex($s[3+$offset]));
}
function FirstSeen ($s,$offset)
// 8 FirstSeen FILETIME Time first seen
{
global $jump;
$jump=$jump+8;
return hexdec(bin2hex($s[0+$offset]))&hexdec(bin2hex($s[1+$offset]))&":"&hexdec(bin2hex($s[2+$offset]))&hexdec(bin2hex($s[3+$offset]))&":"&hexdec(bin2hex($s[4+$offset]))&":"&hexdec(bin2hex($s[5+$offset]))&":"&hexdec(bin2hex($s[6+$offset]))&hexdec(bin2hex($s[7+$offset]));
}
function LastSeen ($s,$offset)
// 8 LastSeen FILETIME Time last seen
{
global $jump;
$jump=$jump+8;
return hexdec(bin2hex($s[0+$offset]))&":"&hexdec(bin2hex($s[1+$offset]))&":"&hexdec(bin2hex($s[2+$offset]))&":"&hexdec(bin2hex($s[3+$offset]))&":"&hexdec(bin2hex($s[4+$offset]))&":"&hexdec(bin2hex($s[5+$offset]))&":"&hexdec(bin2hex($s[6+$offset]))&":"&hexdec(bin2hex($s[7+$offset]));
}
function BestLat ($s,$offset)
// 8 BestLat double Estimated Latitude
{
global $jump;
$jump=$jump+8;
return hexdec(bin2hex($s[0+$offset]))&":"&hexdec(bin2hex($s[1+$offset]))&":"&hexdec(bin2hex($s[2+$offset]))&":"&hexdec(bin2hex($s[3+$offset]))&":"&hexdec(bin2hex($s[4+$offset]))&":"&hexdec(bin2hex($s[5+$offset]))&":"&hexdec(bin2hex($s[6+$offset]))&":"&hexdec(bin2hex($s[7+$offset]));
}
function BestLong ($s,$offset)
// 8 BestLong double Estimated Longitude
{
global $jump;
$jump=$jump+8;
return hexdec(bin2hex($s[0+$offset]))&":"&hexdec(bin2hex($s[1+$offset]))&":"&hexdec(bin2hex($s[2+$offset]))&":"&hexdec(bin2hex($s[3+$offset]))&":"&hexdec(bin2hex($s[4+$offset]))&":"&hexdec(bin2hex($s[5+$offset]))&":"&hexdec(bin2hex($s[6+$offset]))&":"&hexdec(bin2hex($s[7+$offset]));
}
function DataCount ($s,$offset)
// 4 DataCount uint32 Number of APDATA entries that follow
{
global $jump;
$jump=$jump+4;
return hexdec(bin2hex($s[0+$offset]))+255*hexdec(bin2hex($s[1+$offset]))+255*255*hexdec(bin2hex($s[2+$offset]))+255*255*255*hexdec(bin2hex($s[3+$offset]));
}
function ApData ($s,$length, $offset)
// Variable ApData APDATA[] DataCount APDATA entries
{
global $jump;
$jump=$jump+$length;
return substr($s,$offset,$length);
}
function NameLength ($s, $offset)
// 1 NameLength uint8 Length of Name
{
global $jump;
$jump=$jump+1;
return hexdec(bin2hex($s[0+$offset]));
}
function Name ($s, $length, $offset)
// NameLength Name char[] Name (NameLength characters, no terminating null)
{
global $jump;
$jump=$jump+$length;
return substr($s,$offset,$length);
}
function Channels ($s, $offset)
// 8 Channels uint64 Bit field indicating channel activity
{
global $jump;
$jump=$jump+8;
return hexdec(bin2hex($s[0+$offset]))+255*hexdec(bin2hex($s[1+$offset]))+255*255*hexdec(bin2hex($s[2+$offset]))+255*255*255*hexdec(bin2hex($s[3+$offset]))+255*255*255*255*hexdec(bin2hex($s[4+$offset]))+255*255*255*255*255*hexdec(bin2hex($s[5+$offset]))+255*255*255*255*255*255*hexdec(bin2hex($s[6+$offset]))+255*255*255*255*255*255*255*hexdec(bin2hex($s[7+$offset]));
}
function LastChannel ($s, $offset)
// 4 LastChannel uint32 Last reported channel
{
global $jump;
$jump=$jump+4;
return hexdec(bin2hex($s[0+$offset]))+255*hexdec(bin2hex($s[1+$offset]))+255*255*hexdec(bin2hex($s[2+$offset]))+255*255*255*hexdec(bin2hex($s[3+$offset]));
}
function IPAddress ($s, $offset)
// 4 IPAddress uint32 IP Address
{
global $jump;
$jump=$jump+4;
return hexdec(bin2hex($s[0+$offset])).":".hexdec(bin2hex($s[1+$offset])).":".hexdec(bin2hex($s[2+$offset])).":".hexdec(bin2hex($s[3+$offset]));
}
function MinSignal ($s, $offset)
// 4 MinSignal int32 Minimum reported signal level, dBm
{
global $jump;
$jump=$jump+4;
return hexdec(bin2hex($s[0+$offset]))+255*hexdec(bin2hex($s[1+$offset]))+255*255*hexdec(bin2hex($s[2+$offset]))+255*255*255*hexdec(bin2hex($s[3+$offset]));
}
function MaxNoise ($s, $offset)
// 4 MaxNoise int32 Maximum reported noise level, dBm
{
global $jump;
$jump=$jump+4;
return hexdec(bin2hex($s[0+$offset]))+255*hexdec(bin2hex($s[1+$offset]))+255*255*hexdec(bin2hex($s[2+$offset]))+255*255*255*hexdec(bin2hex($s[3+$offset]));
}
function DataRate ($s, $offset)
// 4 DataRate uint32 Highest reported data rate, units of 100 kbps
{
global $jump;
$jump=$jump+4;
return hexdec(bin2hex($s[0+$offset]))+255*hexdec(bin2hex($s[1+$offset]))+255*255*hexdec(bin2hex($s[2+$offset]))+255*255*255*hexdec(bin2hex($s[3+$offset]));
}
function IPSubnet ($s, $offset)
// 4 IPSubnet uint32 IP Subnet address
{
global $jump;
$jump=$jump+4;
return hexdec(bin2hex($s[0+$offset])).":".hexdec(bin2hex($s[1+$offset])).":".hexdec(bin2hex($s[2+$offset])).":".hexdec(bin2hex($s[3+$offset]));
}
function IPMask ($s, $offset)
// 4 IPMask uint32 IP Subnet mask
{
global $jump;
$jump=$jump+4;
return hexdec(bin2hex($s[0+$offset])).":".hexdec(bin2hex($s[1+$offset])).":".hexdec(bin2hex($s[2+$offset])).":".hexdec(bin2hex($s[3+$offset]));
}
function ApFlags ($s, $offset)
// 4 ApFlags uint32 Miscellaneous Flags
{
global $jump;
$jump=$jump+4;
return hexdec(bin2hex($s[0+$offset]))+255*hexdec(bin2hex($s[1+$offset]))+255*255*hexdec(bin2hex($s[2+$offset]))+255*255*255*hexdec(bin2hex($s[3+$offset]));
}
function IELength ($s, $offset)
// 4 IELength uint32 Number of bytes that follow (0 except when using NDIS 5.1 with a WPA capable driver)
{
global $jump;
$jump=$jump+4;
return hexdec(bin2hex($s[0+$offset]))+255*hexdec(bin2hex($s[1+$offset]))+255*255*hexdec(bin2hex($s[2+$offset]))+255*255*255*hexdec(bin2hex($s[3+$offset]));
}
function InformationElements ($s,$length, $offset)
// IELength InformationElements uint8[] 802.11 Information Elements
{
global $jump;
$jump=$jump+$length;
return substr($s,$offset,$length);
}
function APInfo($s, $offset, $number)
//Variable ApInfo APINFO[] ApCount APINFO entries
{
global $jump;
for ($i=1; $i<=$number; $i++)
{
global $jump;
echo $jump;
$SSIDLength = SSIDLength($s,$jump);
echo "SSIDLength = ".$SSIDLength;
echo "<br>";
echo "SSID = ".SSID($s, $SSIDLength, $jump);
echo "<br>";
echo "BSSID = ".BSSID($s,$jump);
echo "<br>";
echo "MaxSignal = ".MaxSignal($s,$jump);
echo "<br>";
echo "MinNoise = ".MinNoise($s,$jump);
echo "<br>";
echo "MaxSNR = ".MaxSNR($s,$jump);
echo "<br>";
echo "Flags = ".Flags($s,$jump);
echo "<br>";
echo "BeaconInterval = ".BeaconInterval($s,$jump);
echo "<br>";
echo "FirstSeen = ".FirstSeen($s,$jump);
echo "<br>";
echo "LastSeen = ".LastSeen($s,$jump);
echo "<br>";
echo "BestLat = ".BestLat($s,$jump);
echo "<br>";
echo "BestLong = ".BestLong($s,$jump);
echo "<br>";
$DataCount = DataCount($s,$jump);
echo "DataCount = ".$DataCount;
echo "<br>";
echo "ApData = ".ApData($s, $DataCount, $jump);
echo "<br>";
$NameLength = NameLength($s,$jump);
echo "NameLength = ".$NameLength;
echo "<br>";
echo "Name = ".Name($s, $NameLength, $jump);
echo "<br>";
echo "Channels = ".Channels($s,$jump);
echo "<br>";
echo "LastChannel = ".LastChannel($s,$jump);
echo "<br>";
echo "IPAddress = ".IPAddress($s,$jump);
echo "<br>";
echo "MinSignal = ".MinSignal($s,$jump);
echo "<br>";
echo "MaxNoise = ".MaxNoise($s,$jump);
echo "<br>";
echo "DataRate = ".DataRate($s,$jump);
echo "<br>";
echo "IPSubnet = ".IPSubnet($s,$jump);
echo "<br>";
echo "IPMask = ".IPMask($s,$jump);
echo "<br>";
echo "ApFlags = ".ApFlags($s,$jump);
echo "<br>";
$IELength = IELength($s,$jump);
echo "IELength = ".$IELength;
echo "<br>";
echo "InformationElements = ".InformationElements($s, $IELength, $jump);
echo "<hr>";
}
}
// Read the file and put the content in a string
$filename = "netstumbler.ns1";
$handle = fopen ($filename, "r");
$contents = fread ($handle, filesize ($filename));
fclose ($handle);
echo "Signature of the file = ".dwSignature($contents,$jump);
echo "<br>";
echo "File version = ".dwFileVer($contents,$jump);
echo "<br>";
$APCount = ApCount($contents,$jump);
echo " Number of AP = ".$APCount;
echo "<hr>";
echo APInfo($contents,$jump,$APCount);
php?>
Just put the script on your webserver, a ns1 file called netstumbler.ns1 and call the script.
The problems are :
- Some info are not correctly converted
- I only display 1 AP (because of IELength)
I you want to enhance this script... contact me to help me.
It's GPL so do what you want with it...
Cordially
Jean CARTIER
|