What is the best way to use Linux Syntax within Python?

I am developing my own tools for Bug Bounties / Pentesting and I need to run a lot of Linux commands out of my Python scripts. I am wondering what is the best / the cleanest way to run Linux syntax from Python?

So far, I am using subprocess.call. I have been using os.system in the past but migrated everything over to subprocess as I have learned that os.system was deprecated.

A sample of how I write my code:

# Processing Files print(green + "### Processing Results... ###" + white) subprocess.call(     "cat /home/ceofreak/SRV/scans/{project}/{target}/subfinder.txt /home/ceofreak/SRV/scans/{project}/{target}/amass.txt /home/ceofreak/SRV/scans/{project}/{target}/assetfinder.txt > /home/ceofreak/SRV/scans/{project}/{target}/subtemp.txt".format(target=target, project=project), shell=True) subprocess.call(     "sort /home/ceofreak/SRV/scans/{project}/{target}/subtemp.txt | uniq | httprobe > /home/ceofreak/SRV/scans/{project}/{target}/gowitness.txt".format(target=target, project=project), shell=True) subprocess.call(     "sort /home/ceofreak/SRV/scans/{project}/{target}/subtemp.txt | uniq | httprobe | sed 's/https\?:\/\///' > /home/ceofreak/SRV/scans/{project}/{target}/subdomains-sorted.txt".format(target=target, project=project), shell=True) subprocess.call(     "sort /home/ceofreak/SRV/scans/{project}/{target}/subdomains-sorted.txt | uniq > /home/ceofreak/SRV/scans/{project}/{target}/subdomains-final.txt".format(target=target, project=project), shell=True) 

As you can probably see, the code gets very ugly very quick. I want to learn how to make this cleaner before I continue on a potentially wrong path.

Would be great to get some insights as I am not a developer and I am mostly learning by doing.

Thanks you a lot 🙂

Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.