No Description

InjectionParserTest.py 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. from SQLInjection import *
  2. if __name__ == '__main__':
  3. sqlI = SQLInjection()
  4. # Test 1
  5. sample = """select cat from dog where casa=1 ;"""
  6. u_input = """select cat from dog where casa=2 ;"""
  7. print "Test 1"
  8. print "Sample: ", sample
  9. print "User In: ", u_input
  10. print "Is Valid?: ", sqlI.validateParser(sample, u_input)
  11. print
  12. # Test 2
  13. u_input = """select cat from dog where casa=1 and cat="miau" ;"""
  14. print "Test 1"
  15. print "Sample: ", sample
  16. print "User In: ", u_input
  17. print "Is Valid?: ", sqlI.validateParser(sample, u_input)
  18. print
  19. # Interactive Example with user input
  20. print "Follow the instruction and then try to inject SQL."
  21. while True:
  22. try:
  23. s = raw_input("Input a number> ")
  24. except EOFError:
  25. break
  26. u_input = """select cat from dog where casa=%s ;""" %s
  27. print "User query: %s" % u_input
  28. try:
  29. print "Is Valid?: ", sqlI.validateParser(sample, u_input)
  30. s_ast, u_ast = sqlI.getLastAsts()
  31. print "Sample AST: "
  32. sqlI.print_ast(s_ast)
  33. print
  34. print "User AST: "
  35. sqlI.print_ast(u_ast)
  36. print
  37. except:
  38. print "False"