/scripts/linux/squid.sh

https://github.com/Bludge0n/Honeyd · Shell · 137 lines · 111 code · 21 blank · 5 comment · 6 complexity · 6500e34d4218b3b97bd2c218243e8dd9 MD5 · raw file

  1. #!/bin/bash
  2. #
  3. # by Fabian Bieker <fabian.bieker@web.de>
  4. # modified by DataSoft Corporation
  5. . scripts/misc/base.sh
  6. SRCIP=$1
  7. SRCPORT=$2
  8. DSTIP=$3
  9. DSTPORT=$4
  10. STRINGSFILE=$5
  11. VERSION=`perl -nle '/SQUID_VERSION (.*)/ and print $1' < $STRINGSFILE`
  12. SERVICE="squid/PROXY"
  13. HOST="serv"
  14. LOG="/var/log/honeyd/web.log"
  15. REQUEST=""
  16. my_start
  17. while read name; do
  18. # remove control-characters
  19. name=`echo $name | sed s/[[:cntrl:]]//g`
  20. LINE=`echo "$name" | egrep -i "[a-z:]"`
  21. if [ -z "$LINE" ]
  22. then
  23. break
  24. fi
  25. echo "$name" >> $LOG
  26. NEWREQUEST=`echo "$name" | egrep -i "(GET|POST) [a-z0-9\./:-\?]+ HTTP/1\.(0|1)"`
  27. if [ ! -z "$NEWREQUEST" ] ; then
  28. REQUEST="GETPOST"
  29. fi
  30. NEWREQUEST=`echo "$name" | egrep -i "CONNECT [a-z0-9\./:-\?]+"`
  31. if [ ! -z "$NEWREQUEST" ] ; then
  32. REQUEST="CONNECT"
  33. fi
  34. done
  35. if [ -z "$REQUEST" ] ; then
  36. cat << _eof_
  37. HTTP/1.0 400 Bad Request
  38. Server: $VERSION
  39. Mime-Version: 1.0
  40. Date: $DATE
  41. Content-Type: text/html
  42. Expires: $DATE
  43. X-Squid-Error: ERR_INVALID_REQ 0
  44. X-Cache: MISS from $HOST.$DOMAIN
  45. X-Cache-Lookup: NONE from $HOST.$DOMAIN:$2
  46. Proxy-Connection: close
  47. <HTML><HEAD>
  48. <TITLE>ERROR: The requested URL could not be retrieved</TITLE>
  49. </HEAD><BODY>
  50. <H1>ERROR</H1>
  51. <H2>The requested URL could not be retrieved</H2>
  52. <HR>
  53. <P>
  54. While trying to process the request:
  55. <PRE>
  56. $name
  57. </PRE>
  58. <P>
  59. The following error was encountered:
  60. <UL>
  61. <LI>
  62. <STRONG>
  63. Invalid Request
  64. </STRONG>
  65. </UL>
  66. <P>
  67. Some aspect of the HTTP Request is invalid. Possible problems:
  68. <UL>
  69. <LI>Missing or unknown request method
  70. <LI>Missing URL
  71. <LI>Missing HTTP Identifier (HTTP/1.0)
  72. <LI>Request is too large
  73. <LI>Content-Length missing for POST or PUT requests
  74. <LI>Illegal character in hostname; underscores are not allowed
  75. </UL>
  76. <P>Your cache administrator is <A HREF="mailto:webcache@$HOST.DOMAIN">webcache@$HOST.$DOMAIN</A>.
  77. _eof_
  78. my_stop
  79. fi
  80. sleep 5
  81. cat << _eof_
  82. HTTP/1.0 400 CONNECT_FAIL
  83. Server: $VERSION
  84. Mime-Version: 1.0
  85. Date: $DATE
  86. Content-Type: text/html
  87. Expires: $DATE
  88. X-Squid-Error: ERR_CONNECT_FAIL 0
  89. X-Cache: MISS from $HOST.$DOMAIN
  90. X-Cache-Lookup: NONE from $HOST.$DOMAIN:$2
  91. Proxy-Connection: close
  92. <HTML><HEAD>
  93. <TITLE>ERROR: The requested URL could not be retrieved</TITLE>
  94. </HEAD><BODY>
  95. <H1>ERROR</H1>
  96. <H2>The requested URL could not be retrieved</H2>
  97. <HR>
  98. <P>
  99. While trying to retrieve the URL:
  100. <A HREF="$name">$name</A>
  101. <P>
  102. The following error was encountered:
  103. <UL>
  104. <LI>
  105. <STRONG>
  106. Connection Failed
  107. </STRONG>
  108. </UL>
  109. <P>
  110. The system returned:
  111. <PRE><I>CONNECTION TIMEOUT</I></PRE>
  112. <P>
  113. The remote host or network may be down. Please try the request again.
  114. <P>Your cache administrator is <A HREF="mailto:webcache@$HOST.DOMAIN">webcache@$HOST.$DOMAIN</A>.
  115. _eof_
  116. my_stop