Code Review: Initialization
Setup
Clone sqlmap:
git clone https://github.com/sqlmapproject/sqlmap.gitI recommend reading the source code in VScode.
sqlmap.py
sqlmap.py is the entrance of sqlmap. An attacker would run:
python3 sqlmap.py -u <url> --usersIt basically does the following things:
...
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
pass
except SystemExit:
raise
except:
traceback.print_exc()
finally:
# Reference: http://stackoverflow.com/questions/1635080/terminate-a-multi-thread-python-program
if threading.active_count() > 1:
os._exit(getattr(os, "_exitcode", 0))
else:
sys.exit(getattr(os, "_exitcode", 0))
else:
# cancelling postponed imports (because of CI/CD checks)
__import__("lib.controller.controller")main
Take a look at the main function:
Pay attention to these 5 functions:
dirtyPatches()resolveCrossReferences()checkEnvironment()setPaths()banner()
We shall track them down one after another.
dirtyPatches()
This function can be found at lib.core.patch:
It is called "dirty patch" since all it does is some dirty work, which is not really important for main functionalities.
resolveCrossReference()
Here is an example of cross reference:
This is kind of similar to a "deadlock" situation. The function resolveCrossReference() intends to solve this problem.
This function can be found at lib.core.patch:
checkEnvironment()
This function can be found at sqlmap.py:
setPaths()
banner()
Last updated
Was this helpful?