Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for obscure.pl

(view source code of obscure.pl as plain text)

  1. #! perl
  2.  
  3. # Run this script without command line arguments for an explanation of the technique used to obscure URLs
  4.  
  5. # Store the screen messages in variables
  6. $header  = "\nObscure.pl,  Version 1.10\n";
  7. $header  = $header."Obscure an URL by using decimal IP address and fake login name.\n";
  8. $syntax  = $syntax."Usage:  OBSCURE.PL  url  [ -DEBUG ]\n\n";
  9. $syntax  = $syntax."Where:  \"url\"   can be any valid URL, host name or IP address\n";
  10. $syntax  = $syntax."        -DEBUG  displays intermediate results\n";
  11. $example = "Explanation:\n";
  12. $example = $example."Let us take the fictional http://somehost.com/sources/ and let's assume\n";
  13. $example = $example."somehost.com's IP address is 1.2.3.4. The decimal representation of the\n";
  14. $example = $example."IP address is: 1 * 256^3 + 2 * 256^2 + 3 * 256 + 4 = 16909060\n";
  15. $example = $example."(try pinging 16909060, it will show 1.2.3.4 as the address being pinged)\n";
  16. $example = $example."So the URL could also be written as http://16909060/sources/\n";
  17. $example = $example."Any URL may be preceded with a (fake) user ID followed by an \@\n";
  18. $example = $example."So we can further obscure the URL by adding a (fake) host as login name:\n";
  19. $example = $example."http://fake.host\@16909060/sources/ still points to http://somehost.com/sources/\n";
  20. $footer  = "Note:   Security settings of your browser may block use of decimal addresses\n\n";
  21. $footer  = $footer."Written by Rob van der Woude\nhttp://www.robvanderwoude.com\n";
  22.  
  23. # Show help message if no arguments were specified
  24. if ( !@ARGV[0] ) {
  25. 	die "$header\n$syntax\n$example\n$footer";
  26. }
  27.  
  28. # Parse command line arguments
  29. $debug = 0;
  30. $error = 0;
  31. foreach ( @ARGV ) {
  32. 	SWITCH: {
  33. 		if ( uc( $_ ) eq "-DEBUG" ) {
  34. 			$debug = 1;
  35. 			last SWITCH;
  36. 		}
  37. 		if ( $_ =~ m/^(((?:ht|f)tp):\/\/)?([^\/]{5,})(\/.*)?$/i ) {
  38. 			$url   = $_;
  39. 			$protf = $1;
  40. 			$prota = $2;
  41. 			$host  = $3;
  42. 			$path  = $4;
  43. 			last SWITCH;
  44. 		}
  45. 		# If you arrived at this part of the code,
  46. 		# an invalid argument was specified, so we
  47. 		# abort with a help message
  48. 		die "$header\n$syntax\n$example\n$footer";
  49. 	}
  50. }
  51.  
  52. # Show help message if invalid arguments were specified
  53. if ( !$host ) {
  54. 	die "$header\n$syntax\n$example\n$footer";
  55. }
  56.  
  57. # If a hostname was specified, convert it to an IP address
  58. if ( $host =~ m/\d+\.\d+\.\d+\.\d+/ ) {
  59. 	$ip = $host;
  60. } else {
  61. 	`ping $host -n 1 -w 500` =~ /^[^\[]+\[(\d+\.\d+\.\d+\.\d+)\]/;
  62. 	$ip = "$1";
  63. }
  64.  
  65. # Check if we now have a valid IP address, abort if not
  66. if ( $ip =~ m/^(\d+)\.(\d+)\.(\d+)\.(\d+)/ ) {
  67. 	if ( $1 > 255 or $2 > 255 or $3 > 255 or $4 > 255 ) {
  68. 		die"\nERROR: Invalid IP address\n\n\n$header\n$syntax\n$footer";
  69. 	}
  70. 	$obsc = (( $1 * 256 + $2 ) * 256 + $3 ) * 256 + $4;
  71. } else {
  72. 	die "\nERROR: Invalid host name or host not online\n\n\n$header\n$syntax\n$footer";
  73. }
  74.  
  75. # Display the result
  76. print "$header\n$footer\n\n";
  77.  
  78. # Display intermediate results when -DEBUG switch was specified
  79. if ( $debug ) {
  80. 	print "URL        = $url\n",
  81. 	      "Protocol   = $prota\n",
  82. 	      "Host name  = $host\n",
  83. 	      "IP address = $ip\n",
  84. 	      "Decimal IP = $obsc\n",
  85. 	      "Path       = $path\n\n";
  86. }
  87.  
  88. print "Obscured URL examples:\n\n   $protf$obsc$path\n",
  89.       "   $protf"."www.whateveryoulike.here\@$obsc$path\n";
  90.  

page last modified: 2024-04-16; loaded in 0.0141 seconds