Visual Studios - Nmap not found in Path, Creating Basic port scanner Python310 - python-3.x

Firstly, I am following the tutorial at FreecodeCamp (https://www.freecodecamp.org/learn/information-security/python-for-penetration-testing/developing-an-nmap-scanner-part-1) - I may discontinue as there is so much ambiguity and little things wrong.. I honestly just want to follow a tutorial and have it work with what is done in the tutorial. X.X
import nmap
scanner = nmap.PortScanner()
print("Welcome, this is a simple Nmap automation tool.")
print("-----------------------------------------------")
ip_addr = input("Please Enter the IP you want to scan.")
print("The IP you entered is: ", ip_addr)
#Sanitize input
type(ip_addr)
c:\Users\WaffWaffles\Desktop\Python Projects>py scanner.py
Traceback (most recent call last):
File "c:\Users\WaffWaffles\Desktop\Python Projects\scanner.py", line 4, in
scanner = nmap.PortScanner()
File "C:\Users\WaffWaffles\AppData\Local\Programs\Python\Python310\lib\site-packages\nmap\nmap.py", line 136, in init
raise PortScannerError(
nmap.nmap.PortScannerError: 'nmap program was not found in path. PATH is : C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\metasploit-framework\bin\;C:\Users\WaffWaffles\AppData\Local\Programs\Python\Python310\Scripts\;C:\Users\WaffWaffles\AppData\Local\Programs\Python\Python310\;"C:\Program Files (x86)\Nmap";C:\Users\WaffWaffles\AppData\Local\Programs\Microsoft VS Code\bin'
When I add
#!\C:\Users\WaffWaffles\AppData\Local\Programs\Python\Python310
to the top I get
c:\Users\WaffWaffles\Desktop\Python Projects>py scanner.py
Unable to create process using '\C:\Users\WaffWaffles\AppData\Local\Programs\Python\Python310\ scanner.py'
I have python-nmap installed through py -m install python-nmap too.

Related

Using Sublime to edit Yocto files, leads to fail to start bitbake server

If I open my Yocto project's folder with Sublime under Ubuntu 16.04 and try to build with:
bitbake <image>
I get these errors:
ERROR: Unable to start bitbake server (None)
ERROR: Server log for this session (/local/STM32MP15-Ecosystem-v1.1.0/Distribution-Package/openstlinux-4.19-thud-mp1-19-10-09/build-openstlinuxeglfs-stm32mp1-sw25v00/bitbake-cookerdaemon.log):
--- Starting bitbake server pid 4602 at 2020-02-01 02:59:00.519051 ---
Traceback (most recent call last):
File "/local/STM32MP15-Ecosystem-v1.1.0/Distribution-Package/openstlinux-4.19-thud-mp1-19-10-09/layers/openembedded-core/bitbake/lib/bb/daemonize.py", line 83, in createDaemon
function()
File "/local/STM32MP15-Ecosystem-v1.1.0/Distribution-Package/openstlinux-4.19-thud-mp1-19-10-09/layers/openembedded-core/bitbake/lib/bb/server/process.py", line 469, in _startServer
self.cooker = bb.cooker.BBCooker(self.configuration, self.featureset)
File "/local/STM32MP15-Ecosystem-v1.1.0/Distribution-Package/openstlinux-4.19-thud-mp1-19-10-09/layers/openembedded-core/bitbake/lib/bb/cooker.py", line 210, in __init__
self.initConfigurationData()
File "/local/STM32MP15-Ecosystem-v1.1.0/Distribution-Package/openstlinux-4.19-thud-mp1-19-10-09/layers/openembedded-core/bitbake/lib/bb/cooker.py", line 396, in initConfigurationData
self.add_filewatch(mc.getVar("__base_depends", False), self.configwatcher)
File "/local/STM32MP15-Ecosystem-v1.1.0/Distribution-Package/openstlinux-4.19-thud-mp1-19-10-09/layers/openembedded-core/bitbake/lib/bb/cooker.py", line 306, in add_filewatch
watcher.add_watch(f, self.watchmask, quiet=False)
File "/local/STM32MP15-Ecosystem-v1.1.0/Distribution-Package/openstlinux-4.19-thud-mp1-19-10-09/layers/openembedded-core/bitbake/lib/pyinotify.py", line 1924, in add_watch
raise WatchManagerError(err, ret_)
pyinotify.WatchManagerError: add_watch: cannot watch /local/STM32MP15-Ecosystem-v1.1.0/Distribution-Package/openstlinux-4.19-thud-mp1-19-10-09/build-openstlinuxeglfs-stm32mp1-sw25v00/conf WD=-1, Errno=No space left on device (ENOSPC)
ERROR: No space left on device or exceeds fs.inotify.max_user_watches?
ERROR: To check max_user_watches: sysctl -n fs.inotify.max_user_watches.
ERROR: To modify max_user_watches: sysctl -n -w fs.inotify.max_user_watches=<value>.
ERROR: Root privilege is required to modify max_user_watches.
Closing the editor and issue again the command works correctly.
Other editors (like gedit) does not have this behavior.
I know I can live without Sublime, but I want to understand che cause of the errors.
You're running out of inotify watches. Software such as Sublime and the program you're running here (among others) use inotify watches to detect changes to the file system, such as being able to track when files are changing or when the contents of a directory changes.
There's a (user settable) upper limit to the number of watches that can be in use at once, and the rather cryptic error message you're seeing here is a symptom of the limit being reached and the program failing to obtain a watch.
The default value for the maximum inotify watches may not be set high enough on your system for the software (and volume of files) that you're using, but you can change that if you like.
The output at the bottom of your error diagnotic information shows how you can view/adjust the upper limit. The following question also shows how you could do this as well.
https://unix.stackexchange.com/questions/13751/kernel-inotify-watch-limit-reached

Python in Visual Studio Code getting winError[5] Access denied from idescripts

it is my first time posting here so I apologize if this question is not correctly formatted.
I installed VSC to use it in developing STM32 code. I found the damongranlabs idescripts in github that would help greatly. While running the update.py script, I get the winError[5] access denied. VSC is using powershell as a terminal and I am running windows 10 with Python 3.8 32bit.
I have tried running VSC as an admin with no luck.
The following is what I get in powershell after attempting to run the script:
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
Try the new cross-platform PowerShell https://aka.ms/pscore6
PS D:\Development\STM32\cubemxprojects\476EncTest> & d:/Development/STM32/cubemxprojects/476EncTest/ideScripts/update.py
Update started.
Existing '.vscode' folder used.
One STM32CubeMX file found: 476EncTest.ioc
Existing 'Makefile' file found (restored from '.backup').
Copy of file (new name: Makefile): D:/Development/STM32/cubemxprojects/476EncTest/Makefile.backup
Makefile 'print-variable' function added.
Valid 'buildData.json' file found.
Valid 'toolsPaths.json' file found.
'toolsPaths.json' file updated!
Enter path(s) to OpenOCD configuration file(s):
Example: 'target/stm32f0x.cfg'. Absolute or relative to OpenOCD /scripts/ folder.
If more than one file is needed, separate with comma.
Paste here and press Enter: C:\Users\omis2\AppData\Roaming\GNUMCUEclipse\GNU MCU Eclipse\OpenOCD\0.10.0-12-20190422-2015\scripts\target\stm32l4x.cfg
Enter path or command for 'stm32SvdPath':
Paste here and press Enter: C:\Users\omis2\AppData\Roaming\GNUMCUEclipse\Keil.STM32L4xx_DFP.2.2.0\CMSIS\SVD\STM32L4x6.svd
ERROR (55 seconds).
Unexpected error occured during 'Update' procedure. Exception:
Traceback (most recent call last):
File "D:\Development\STM32\cubemxprojects\476EncTest\ideScripts\update.py", line 56, in <module>
makefileData = makefile.getMakefileData(makeExePath, gccExePath)
File "D:\Development\STM32\cubemxprojects\476EncTest\ideScripts\updateMakefile.py", line 93, in getMakefileData
projectName = self.getMakefileVariable(makeExePath, gccExePath, self.mkfStr.projectName)[0]
File " D:\Development\STM32\cubemxprojects\476EncTest\ideScripts\updateMakefile.py", line 366, in getMakefileVariable
proc = Popen(arguments, stdout=PIPE)
File "C:\Users\omis2\AppData\Local\Programs\Python\Python38- 32\lib\subprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\omis2\AppData\Local\Programs\Python\Python38- 32\lib\subprocess.py", line 1307, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
PermissionError: [WinError 5] Access is denied
Thanks for any help

Python(3.6): program was not found in path

On Windows 10 (PyCharm IDE), i tried import the pythone-nmap module to get PortScenner.
The code i wrote:
import nmap
ns = nmap.PortScanner()
a = ns.nmap_version()
print(a)
Afterward, i got the following error:
C:\Users\Mind1\AppData\Local\Programs\Python\Python36-32\python.exe
C:/Users/Mind1/PycharmProjects/testNmap/main.py
Traceback (most recent call last):
File "C:/Users/Mind1/PycharmProjects/testNmap/main.py", line 2, in
ns = nmap.PortScanner()
File
"C:\Users\Mind1\AppData\Local\Programs\Python\Python36-32\lib\site-packages\nmap\nmap.py",
line 131, in init
os.getenv('PATH')
nmap.nmap.PortScannerError: 'nmap program was not found in path.
PATH is : C:\Program Files (x86)\Common
Files\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program
Files\Git\cmd;C:\WINDOWS\System32\OpenSSH\;C:\Users\Mind1\AppData\Local\Programs\Python\Python36-32\lib\site-packages\nmap\nmap.py;C:\tizen-studio\tools\ide\bin;C:\Users\Mind1\AppData\Local\Programs\Python\Python36-32\Scripts\;C:\Users\Mind1\AppData\Local\Programs\Python\Python36-32\;C:\Users\Mind1\AppData\Local\Microsoft\WindowsApps;C:\Program
Files\Microsoft VS
Code\bin;C:\Programing\SQLite3;C:\Users\Mind1\AppData\Local\Microsoft\WindowsApps;C:\Program
Files\JetBrains\PyCharm Community Edition
2019.2.3\bin;;C:\Users\Mind1\AppData\Local\Programs\Python\Python36-32\lib\site-packages\nmap\nmap.py;'
My questions are:
Why isn't it found in the path, when it is there at the end of the path?
Why are there 2 semi-colon before the last part of the path?
ps: I tried to add the path within the () of the PortScanner(), but that hasn't worked neither. (Not even when I used the double \ signs.

RuntimeError: Failed to init API, possibly an invalid tessdata path:<>

I am using windows os. Want to detect the text from an image with fontAttributes by tesserocr. But when I am running the python code, I am getting this error -
RuntimeError: Failed to init API, possibly an invalid tessdata path: C:\Program Files (x86)\Tesseract-OCR\tessdata/
i) I have installed -
tesseract-ocr-w32-setup-v5.0.0-alpha.20190623.exe
//(though my system is 64 bit)
ii) Added to path variable (both system and user path) -
C:\Program Files (x86)\Tesseract-OCR
C:\Program Files (x86)\Tesseract-OCR\tessdata
iii) Created new system path variable - TESSDATA_PREFIX and linked path of
tessdata folder, like -
TESSDATA_PREFIX - C:\Program Files (x86)\Tesseract-OCR\tessdata
import pytesseract
import locale
locale.setlocale(locale.LC_ALL, 'C')
from tesserocr import PyTessBaseAPI, RIL, iterate_level,OEM
with PyTessBaseAPI(oem=OEM.TESSERACT_ONLY,lang='bask') as api:
api.SetImageFile('sugar.png')
api.Recognize()
ri = api.GetIterator()
level = RIL.WORD
for r in iterate_level(ri, level):
attrs = r.WordFontAttributes()
symbol = r.GetUTF8Text(level)
print(symbol,attrs)
with PyTessBaseAPI(oem=OEM.TESSERACT_ONLY,lang='bask') as api:
File "tesserocr.pyx", line 1168, in tesserocr._tesserocr.PyTessBaseAPI.__cinit
__
File "tesserocr.pyx", line 1181, in tesserocr._tesserocr.PyTessBaseAPI._init_a
pi
RuntimeError: Failed to init API, possibly an invalid tessdata path: C:\Program
Files (x86)\Tesseract-OCR\tessdata/
Probably you don't have the .traineddata files in your system. you have to copy it from
C:\Program Files\Tesseract-OCR\tessdata
and paste all the data files to your directory , I'd suggest create a virtual environment ans then use it

Mercurial largefiles not working on Windows Server 2008

I'm trying to get the largefiles extension working on a mercurial server under Windows Server 2008 / IIS 7.5 with the hgweb.wsgi script.
When I clone a repo with largefiles locally (but using https://domain/, not a file system path) everything gets cloned fine, but when I try it on a different machine I get abort: remotestore: largefile XXXXX is missing
Here's the verbose output:
requesting all changes
adding changesets
adding manifests
adding file changes
added 1 changesets with 177 changes to 177 files
calling hook changegroup.lfiles: <function checkrequireslfiles at 0x0000000002E00358>
updating to branch default
resolving manifests
getting .hglf/path/to.file
...
177 files updated, 0 files merged, 0 files removed, 0 files unresolved
getting changed largefiles
getting path/to.file:c0c81df934cd72ca980dd156984fa15987e3881d
abort: remotestore: largefile c0c81df934cd72ca980dd156984fa15987e3881dis missing
Both machines have the extension working. I've tried disabling the firewall but that didn't help. Do I have to do anything to set up the extension besides adding it to mercurial.ini?
Edit: If I delete the files from the server's AppData\Local\largefiles\ directory, I get the same error when cloning on the server, unless I use a filesystem path to clone, in which case the files are added back to `AppData\Local\largefiles\'
Edit 2: Here's the debug output and traceback:
177 files updated, 0 files merged, 0 files removed, 0 files unresolved
getting changed largefiles
using http://domain
sending capabilities command
getting largefiles: 0/75 lfile (0.00%)
getting path/to.file:64f2c341fb3b1adc7caec0dc9c51a97e51ca6034
sending statlfile command
Traceback (most recent call last):
File "mercurial\dispatch.pyo", line 87, in _runcatch
File "mercurial\dispatch.pyo", line 685, in _dispatch
File "mercurial\dispatch.pyo", line 467, in runcommand
File "mercurial\dispatch.pyo", line 775, in _runcommand
File "mercurial\dispatch.pyo", line 746, in checkargs
File "mercurial\dispatch.pyo", line 682, in <lambda>
File "mercurial\util.pyo", line 463, in check
File "mercurial\commands.pyo", line 1167, in clone
File "mercurial\hg.pyo", line 400, in clone
File "mercurial\extensions.pyo", line 184, in wrap
File "hgext\largefiles\overrides.pyo", line 629, in hgupdate
File "hgext\largefiles\lfcommands.pyo", line 416, in updatelfiles
File "hgext\largefiles\lfcommands.pyo", line 398, in cachelfiles
File "hgext\largefiles\basestore.pyo", line 80, in get
File "hgext\largefiles\remotestore.pyo", line 56, in _getfile
Abort: remotestore: largefile 64f2c341fb3b1adc7caec0dc9c51a97e51ca6034 is missing
The _getfile function throws an exception because the statlfile command returns that the file wasn't found.
I've never used python myself, so I don't know what I'm doing while trying to debug this :D
AFAIK the statlfile command gets executed on the server so I can't debug it from my local machine. I've tried running python -m win32traceutil on the server, but it doesn't show anything. I also tried setting accesslog and errorlog in the server's mercurial config file, but it doesn't generate them.
I run hg through the hgweb.wsgi script, and I have no idea if/how I can get into the python debugger using that, but if I could get the debugger running on the server I could narrow down the problem...
Finally figured it out, the extension tries to write temporary files to %windir%\System32\config\systemprofile\AppData\Local, which was causing permission errors. The call was wrapped in a try-catch block that ended up returning the "file not found" error.
I'm just posting this for anyone else coming into the thread from a search.
There's currently an issue using the largefiles extension in the mercurial python module when hosted via IIS. See this post if you're encountering issues pushing large changesets (or large files) to IIS via TortoiseHg.
The problem ultimlately turns out to be a bug in SSL processing introduced Python 2.7.3 (probably explaining why there are so many unresolve posts of people looking for problems with Mercurial). Rolling back to Python 2.7.2 let me get a little further ahead (blocked at 30Mb pushes instead of 15Mb), but to properly solve the problem I had to install the IISCrypto utility to completely disable transfers over SSLv2.

Resources