Advertisement
Guest User

checkstrip.py

a guest
Nov 29th, 2014
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.02 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. # Copyright 2013, 2014 Philipp Winter <phw@nymity.ch>
  4. #
  5. # This file is part of exitmap.
  6. #
  7. # exitmap is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # exitmap is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with exitmap.  If not, see <http://www.gnu.org/licenses/>.
  19.  
  20. """
  21. Module to detect SSL stripping by Tor exit nodes.
  22. """
  23.  
  24. import urllib2
  25.  
  26. import log
  27.  
  28. logger = log.get_logger()
  29.  
  30. # exitmap needs this variable to figure out which relays can exit to the given
  31. # destination(s).
  32.  
  33. destinations = [("blockchain.info", 80)]
  34.  
  35.  
  36. def probe(exit_fpr, cmd):
  37.     """
  38.    Probe the given exit relay and look for check.tp.o false negatives.
  39.    """
  40.  
  41.     logger.debug("Now probing exit relay "
  42.                  "<https://globe.torproject.org/#/relay/%s>." % exit_fpr)
  43.  
  44.     newurl = None
  45.  
  46.     try:
  47.         newurl = urllib2.urlopen("http://blockchain.info",
  48.                                  timeout=10).geturl()
  49.     except Exception as err:
  50.         logger.debug("urllib2.urlopen says: %s" % err)
  51.  
  52.     if not newurl:
  53.         return
  54.  
  55.     if newurl.rstrip("/") != "https://blockchain.info":
  56.         logger.error("Detected SSL stripping on"
  57.                      "<https://globe.torproject.org/#/relay/%s>: got %r" % (exit_fpr, newurl))
  58.     else:
  59.         logger.debug("Exit relay <https://globe.torproject.org/#/relay/%s> "
  60.                      "passed SSL stripping test." % exit_fpr)
  61.  
  62.  
  63. def main():
  64.     """
  65.    Entry point when invoked over the command line.
  66.    """
  67.  
  68.     probe("n/a", None)
  69.  
  70.     return 0
  71.  
  72.  
  73. if __name__ == "__main__":
  74.     exit(main())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement