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 IPHex=
  15. SET IPDec=
  16. SET Prot=
  17. SET URL=
  18.  
  19. :: Parse command line arguments
  20. ECHO. %* | FIND /I " -DEBUG " >NUL
  21. IF ERRORLEVEL 1 (SET DEBUG=0) ELSE (SET DEBUG=1)
  22. IF %DEBUG%==0 (
  23. 	SET URL=%~1
  24. ) ELSE (
  25. 	IF /I [%1]==[-DEBUG] SET URL=%~2
  26. 	IF /I [%2]==[-DEBUG] SET URL=%~1
  27. )
  28. IF NOT DEFINED URL GOTO Syntax
  29. ECHO "%URL%" | FINDSTR /R /I /C:"tps*://" >NUL
  30. IF NOT ERRORLEVEL 1 (
  31. 	FOR /F "tokens=1* delims=:" %%A IN ("%URL%") DO (
  32. 		SET Prot=%%A
  33. 		SET URL=%%B
  34. 	)
  35. )
  36. IF DEFINED Prot (
  37. 	SET Prot=%Prot%://
  38. 	SET URL=%URL:~2%
  39. )
  40. FOR /F "tokens=1* delims=/" %%A IN ("%URL%") DO (
  41. 	SET Host=%%A
  42. 	SET Dir=%%B
  43. )
  44. IF DEFINED Dir (
  45. 	SET Dir=/%Dir%
  46. ) ELSE (
  47. 	ECHO."%URL%" | FIND "/" >NUL
  48. 	IF NOT ERRORLEVEL 1 SET Dir=/%Dir%
  49. )
  50.  
  51. :: Check if specified host name is available
  52. FOR /F "tokens=2 delims=[]" %%A IN ('PING %Host% -4 -n 1 2^>NUL') DO SET IPDec=%%A
  53. IF NOT DEFINED IPDec (
  54. 	ECHO Host name invalid or host not available
  55. 	GOTO:EOF
  56. )
  57.  
  58. :: Call subroutine to convert IP address to decimal number
  59. FOR /F "tokens=1-4 delims=." %%A IN ("%IPDec%") DO CALL :Hex2Dec %%A %%B %%C %%D
  60.  
  61. :: Display intermediate results if -DEBUG switch was used
  62. IF "%DEBUG%"=="1" (
  63. 	ECHO.
  64. 	SET URL
  65. 	SET Prot
  66. 	SET Host
  67. 	SET IPDec
  68. 	SET IPHex
  69. 	SET Dir
  70. 	ECHO.
  71. )
  72.  
  73. :: Display the result
  74. ECHO.
  75. ECHO Obscured URL examples:
  76. ECHO.
  77. ECHO    %Prot%%IPHex%%Dir%
  78. ECHO    %Prot%fake.host@%IPHex%%Dir%
  79.  
  80. :: Done
  81. ENDLOCAL
  82. GOTO:EOF
  83.  
  84.  
  85. :Dec2Hex
  86. SETLOCAL ENABLEDELAYEDEXPANSION
  87. SET DecDigits=%1
  88. IF "%DecDigits:~0,1%"=="0" SET DecDigits=%DecDigits:~1%
  89. IF "%DecDigits:~0,1%"=="0" SET DecDigits=%DecDigits:~1%
  90. SET /A MSD = %DecDigits% / 16
  91. SET /A LSD = %DecDigits% - 16 * %MSD%
  92. SET Convert=0123456789ABCDEF
  93. SET MSD=!Convert:~%MSD%,1!
  94. SET LSD=!Convert:~%LSD%,1!
  95. ENDLOCAL && SET HexDigits=%MSD%%LSD%
  96. GOTO:EOF
  97.  
  98.  
  99. :Hex2Dec
  100. CALL :Dec2Hex %1
  101. SET IPHex=0x%HexDigits%
  102. CALL :Dec2Hex %2
  103. SET IPHex=%IPHex%%HexDigits%
  104. CALL :Dec2Hex %3
  105. SET IPHex=%IPHex%%HexDigits%
  106. CALL :Dec2Hex %4
  107. SET IPHex=%IPHex%%HexDigits%
  108. GOTO:EOF
  109.  
  110.  
  111. :Syntax
  112. ECHO Obscure.bat,  Version 1.01 for Windows NT4 and later
  113. ECHO Obscure the specified URL by converting the host name to a hexadecimal
  114. ECHO IP address and by adding a fake hostname as a login name.
  115. ECHO.
  116. ECHO Usage:  OBSCURE.BAT  url  [ -DEBUG ]
  117. ECHO Where:  "url"   can be any valid URL, host name or IP address
  118. ECHO         -DEBUG  displays intermediate results
  119. ECHO.
  120. ECHO Explanation: Let's take the fictional http://somehost.com/sources/ and
  121. ECHO let's assume somehost.com's IP address is 11.12.13.14.
  122. ECHO The hexadecimal representation of the IP address is: 0x0B0C0D0E.
  123. ECHO Try pinging 0x0B0C0D0E, it will show 11.12.13.14 as the address being pinged.
  124. ECHO So the URL could also be written as http://0x0B0C0D0E/sources/.
  125. ECHO Any URL may be preceded with a user ID followed by an @.
  126. ECHO So we can further obscure the URL by adding a fake host name:
  127. ECHO http://fake.host@0x0B0C0D0E/ still points to http://somehost.com/
  128. ECHO.
  129. ECHO Note:   Browser security settings may block use of hexadecimal addresses,
  130. ECHO         especially if preceded by a login that is not required by the site
  131. ECHO.
  132. ECHO Written by Rob van der Woude
  133. ECHO https://www.robvanderwoude.com
  134.  
  135. IF "%OS%"=="Windows_NT" EXIT /B 1
  136.  

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