Support
Quality
Security
License
Reuse
kandi has reviewed theHarvester and discovered the below as its top functions. This is intended to give you an instant insight into theHarvester implemented functionality, and help decide if they suit your requirements.
Get all kandi verified functions for this library.
Get all kandi verified functions for this library.
E-mails, subdomains and names Harvester - OSINT
See all related Code Snippets
QUESTION
Python Error using subprocess without shell=false and variable from an array
Asked 2019-Mar-02 at 23:08I have the code snippet that works with shell=True which isn't secure and when i attempt to remove shell=True and include shell=False the program errors out
The code is below:
cmd = "git clone https://github.com/{} &"
#define a worker function
def worker():
while True:
item = q.get()
subprocess.Popen(cmd.format(item))
q.task_done()
I get the error below:
File "rapid.py", line 56, in worker
subprocess.Popen(cmd.format(item))
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 775, in __init__
restore_signals, start_new_session)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 1522, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'git clone https://github.com/laramies/theHarvester.git &': 'git clone https://github.com/laramies/theHarvester.git &'
if i add shell = True to the subprocess line it runs just fine (see below) but then code factor flags it as insecure code. Any way to do this without shell = true?
cmd = "git clone https://github.com/{} &"
#define a worker function
def worker():
while True:
item = q.get()
subprocess.Popen(cmd.format(item), shell = True)
q.task_done()
ANSWER
Answered 2019-Mar-02 at 23:08The command is being passed to subprocess.Popen
as a string. This works when using shell=True
because the shell can accept a command as a single string. But when shell=False
, Popen expects the command as a list of arguments, the first one being the full path of the program to run. (This is assuming you're on a POSIX machine, not Windows.)
Essentially, the code says "Run a program called git clone https://github.com/laramies/theHarvester.git
with no arguments" instead of "Run git
with arguments clone
and https://github.com/laramies/theHarvester.git
".
The &
should also be removed because that is a shell feature and with shell=False
it would be passed to git as an argument it won't understand. You don't need it though, since the process will run in the background anyway.
Something like this should work:
subprocess.Popen(["/usr/bin/git", "clone", "https://github.com/{}".format(item)])
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
No vulnerabilities reported
Save this library and start creating your kit
See Similar Libraries in
Save this library and start creating your kit
Open Weaver – Develop Applications Faster with Open Source