Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for obscure.bat

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

  1. @ECHO OFF
  2. :: Check command line arguments and Windows version
  3. IF [%1]==[] GOTO Syntax
  4. IF [%1]==[/?] GOTO Syntax
  5. IF [%2]==[/?] GOTO Syntax
  6. IF NOT [%3]==[] GOTO Syntax
  7. IF NOT [%2]==[] IF /I NOT [%1]==[-DEBUG] IF /I NOT [%2]==[-DEBUG] GOTO Syntax
  8. IF NOT "%OS%"=="Windows_NT" GOTO Syntax
  9.  
  10. SETLOCAL
  11. :: Initialize local variables
  12. SET Dir=
  13. SET Host=
  14. SET IPDec=
  15. SET IPHex=
  16. SET Manual=
  17. SET Prot=
  18. SET URL=
  19.  
  20. :: Parse command line arguments
  21. ECHO. %* | FIND /I " -DEBUG " >NUL
  22. IF ERRORLEVEL 1 (SET DEBUG=0) ELSE (SET DEBUG=1)
  23. IF %DEBUG%==0 (
  24. 	SET URL=%~1
  25. ) ELSE (
  26. 	IF /I [%1]==[-DEBUG] SET URL=%~2
  27. 	IF /I [%2]==[-DEBUG] SET URL=%~1
  28. )
  29. IF NOT DEFINED URL GOTO Syntax
  30. ECHO "%URL%" | FIND /I "tp://" >NUL
  31. IF NOT ERRORLEVEL 1 FOR /F "tokens=1* delims=:" %%A IN ("%URL%") DO (
  32. 	SET Prot=%%A
  33. 	SET URL=%%B
  34. )
  35. IF DEFINED Prot (
  36. 	SET Prot=%Prot%://
  37. 	SET URL=%URL:~2%
  38. )
  39. FOR /F "tokens=1* delims=/" %%A IN ("%URL%") DO (SET Host=%%A&SET Dir=%%B)
  40. IF DEFINED Dir (
  41. 	SET Dir=/%Dir%
  42. ) ELSE (
  43. 	ECHO."%URL%" | FIND "/" >NUL
  44. 	IF NOT ERRORLEVEL 1 SET Dir=/%Dir%
  45. )
  46.  
  47. :: Check if specified host name is available
  48. FOR /F "tokens=2 delims=[]" %%A IN ('PING %Host% -n 1 2^>NUL') DO SET IPHex=%%A
  49. IF NOT DEFINED IPHex (
  50. 	ECHO Host name invalid or host not available
  51. 	GOTO:EOF
  52. )
  53.  
  54. :: Call subroutine to convert IP address to decimal number
  55. FOR /F "tokens=1-4 delims=." %%A IN ("%IPHex%") DO CALL :Hex2Dec %%A %%B %%C %%D
  56.  
  57. :: Display intermediate results if -DEBUG switch was used
  58. IF %DEBUG%==1 (
  59. 	ECHO.
  60. 	SET URL
  61. 	SET Prot
  62. 	SET Host
  63. 	SET IPHex
  64. 	SET IPDec
  65. 	SET Dir
  66. 	ECHO.
  67. 	IF DEFINED Manual (
  68. 		ECHO Due to limitations in integer size in batch files, you will need to add
  69. 		ECHO 2147483648 to IPDec manually
  70. 	)
  71. )
  72.  
  73. :: Message if decimal IP address exceeds integer limit for batch files
  74. IF DEFINED Manual SET IPDec=[ %IPDec% + 2147483648 ]
  75.  
  76. :: Display the result
  77. ECHO.
  78. ECHO Obscured URL examples:
  79. ECHO.
  80. ECHO    %Prot%%IPDec%%Dir%
  81. ECHO    %Prot%fake.host@%IPDec%%Dir%
  82.  
  83. :: Display another warning message if decimal number exceeds integer limit
  84. IF DEFINED Manual (
  85. 	ECHO.
  86. 	ECHO Please replace "%IPDec%" with the result of the addition,
  87. 	ECHO without the brackets, spaces or quotes!
  88. )
  89.  
  90. :: Done
  91. ENDLOCAL
  92. GOTO:EOF
  93.  
  94.  
  95. :Hex2Dec
  96. :: Check if IP address exceeds integer limit for batch files
  97. IF %1 LSS 128 (
  98. 	SET First=%1
  99. ) ELSE (
  100. 	SET /A First = %1 - 128
  101. 	SET Manual=1
  102. )
  103. :: Convert IP address to decimal number
  104. SET /A IPDec = (( %First% * 256 + %2 ) * 256 + %3 ) * 256 + %4
  105. GOTO:EOF
  106.  
  107.  
  108. :Syntax
  109. ECHO Obscure.bat,  Version 1.00 for Windows NT
  110. ECHO Obscure the specified URL by converting the host name to a decimal IP address
  111. ECHO and by adding a hostname -- either vake or valid -- as a fake login name.
  112. ECHO.
  113. ECHO Usage:  OBSCURE.BAT  url  [ -DEBUG ]
  114. ECHO Where:  "url"   can be any valid URL, host name or IP address
  115. ECHO         -DEBUG  displays intermediate results
  116. ECHO.
  117. ECHO Explanation: Let's take the fictional http://somehost.com/sources/ and let's
  118. ECHO assume somehost.com's IP address is 1.2.3.4. The decimal representation of the
  119. ECHO IP address is: 1 * 256**3 + 2 * 256**2 + 3 * 256 + 4 = 16909060
  120. ECHO Try pinging 16909060, it will show 1.2.3.4 as the address being pinged. So the
  121. ECHO URL could also be written as http://16909060/sources/. Any URL may be preceded
  122. ECHO with a user ID followed by an @. So we can further obscure the URL by adding a
  123. ECHO fake host name: http://fake.host@16909060/ still points to http://somehost.com/
  124. ECHO.
  125. ECHO Notes:  [1] Browser security settings may block use of decimal addresses
  126. ECHO         [2] Due to the integer size limit in batch files, you will need to add
  127. ECHO             2147483648 manually to the displayed decimal IP address for IP
  128. ECHO             addresses 128.0.0.0 and up; if so, a message will be displayed.
  129. ECHO.
  130. ECHO Written by Rob van der Woude
  131. ECHO http://www.robvanderwoude.com
  132.  

page last uploaded: 2017-07-06, 12:37