Program that hide data in repeating whitespace in HTML.
python
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

htmlsteg.py 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-#
  3. # Copyright 2017 Weber Yann <yann.weber@member.fsf.org>
  4. #
  5. # This file is part of HtmlSteg.
  6. #
  7. # HtmlSteg 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. # any later version.
  11. #
  12. # HtmlSteg 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 HtmlSteg. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. import sys
  21. import argparse
  22. from steg import clean_html, hide, unhide
  23. if __name__ == '__main__':
  24. parser = argparse.ArgumentParser(description='Html steganography program')
  25. parser.add_argument('-u', '--unhide', action='store_const',
  26. default=False, const=True,
  27. help="Unhide from input")
  28. parser.add_argument('-i', '--input', metavar='FILE', type=str,
  29. default='-', help='Filename or - for stdin')
  30. parser.add_argument('-o', '--output', metavar='FILE', type=str,
  31. default='-', help='Filename or - for stdout')
  32. parser.add_argument('-s', '--hide', metavar='FILE', type=str,
  33. default='', help="Html filename to hide input in")
  34. args = parser.parse_args()
  35. if len(args.hide) > 0 and args.unhide:
  36. sys.stderr.write('--unhide and --hide cannot be set at same time')
  37. parser.print_help()
  38. exit(1)
  39. try:
  40. if args.output == '-':
  41. fdout = sys.stdout
  42. else:
  43. fdout = open(args.output, 'w+')
  44. if args.input == '-':
  45. data_in = sys.stdin.read()
  46. else:
  47. with open(args.input, 'r') as fdin:
  48. data_in = fdin.read()
  49. except Exception as e:
  50. parser.print_help()
  51. raise e
  52. if args.unhide:
  53. res = unhide(data_in)
  54. fdout.write(res)
  55. elif len(args.hide) > 0:
  56. try:
  57. with open(args.hide, 'r') as fdhtml:
  58. html = fdhtml.read()
  59. except Exception as e:
  60. parser.print_help()
  61. raise e
  62. data_in = bytearray(data_in)
  63. html = clean_html(html)
  64. html = hide(html, data_in)
  65. fdout.write(html)
  66. else:
  67. parser.print_help()
  68. exit(1)