Advertisement
0x00sec_JINX

format.py

Jun 29th, 2016
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.53 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. #   This program is free software: you can redistribute it and/or modify
  4. #   it under the terms of the GNU General Public License as published by
  5. #   the Free Software Foundation, either version 3 of the License, or
  6. #   (at your option) any later version.
  7. #
  8. #   This program is distributed in the hope that it will be useful,
  9. #   but WITHOUT ANY WARRANTY; even without the implied warranty of
  10. #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11. #   GNU General Public License for more details.
  12. #
  13. #   you should have received a copy of the GNU General Public License
  14. #   along with this program.  If not, see <http://www.gnu.org/licenses/>.
  15. #
  16. #   All code posted on my Pastebin is designed for Linux (Debian-based)
  17. #
  18. #   Description:
  19. #       This file takes a text file that is setup like the following...
  20. #           "string1", "string2", "string3"
  21. #       or
  22. #           string1, string2, string3
  23. #       or
  24. #           string1 string2 string3
  25. #
  26. #       It then formats it to the following and replaces the original content...
  27. #           string1
  28. #           string2
  29. #           string3
  30. #
  31. #       Perfect for making a dictionary file for password cracking *wink wink*
  32. #       The different words have to be separated by a space to make the new line
  33.  
  34. import argparse
  35. from subprocess import call
  36.  
  37. def main(filename):
  38.     with open(filename, "r") as inFile:
  39.         with open("/tmp/outFile.txt", "w") as outFile:
  40.             print("\n[*] This will erase the contents inside '%s' and will be replaced with the formatted version.\
  41.                 \n[*] If you still want the contents, copy them into a new file and pass that file into here.\
  42.                 \n[*] Do you wish to continue? [Y/n]" % filename),
  43.             ans = raw_input("")
  44.             if ans.lower() == 'y':
  45.                 pass
  46.             else:
  47.                 return 1
  48.             contents = inFile.read()
  49.             formatted_contents = formatString(contents)
  50.             outFile.write(formatted_contents)
  51.     command = "rm %s && cp /tmp/outFile.txt %s && rm /tmp/outFile.txt" % (filename, filename)
  52.     call(command,shell=True)
  53.     print "[*] File: '%s' was successfully formatted into a dictionary file!\n" % filename
  54.  
  55.  
  56. def formatString(string):
  57.  
  58.     bad_chars = ["\"",","] # add/remove bad characters in here if needed
  59.     listed_string = list(string)
  60.     for x in range(0, len(listed_string)):
  61.  
  62.         if listed_string[x] == " ":
  63.             listed_string[x] = "\n"
  64.         elif listed_string[x] in bad_chars:
  65.             listed_string[x] = ""
  66.         elif listed_string[x] == "\n":
  67.             pass
  68.  
  69.     return "".join(listed_string)
  70.  
  71. parser = argparse.ArgumentParser()
  72. parser.add_argument("fileToFormat",help="The file you want to format",type=str)
  73. argv = parser.parse_args()
  74.  
  75. main(argv.fileToFormat)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement