How can I sniff packets using Scapy without any CMD opened? - python

I'm trying to write a script to sniff some packets and send others according to the sniff.
I also want that script to be completely invisible to the user (so it could only be seen from Task Manager).
I tried changing the script extension to .pyw so it would run with pythonw.exe, and it kind of works. However a PowerShell window opens up and when closed, shuts off the pythonw process as well.
I read some on the web and understood Scapy creates it in order to get access to low level networking requests. I also found code to change it into a regular CMD. However I don't want it to change to another shell type, I want this shell to disappear completely so there's no indication om the desktop that the script is running.
How do I achieve this? Is there a way to request scapy to create this shell as a background process? Or is there a way to move an already running CMD to the background?
Thanks in advance!
PS:
The code to change the PowerShell to CMD is:
POWERSHELL_PROCESS.close()
conf.prog.powershell = None
POWERSHELL_PROCESS.__init__()
After the import, and was found here.

I don’t really understand what you are trying to do
This was a well-known bug in scapy, that opened in some IDE (e.g IDLE), the powershell would be visible. As shown in the link you provided, it has been fixed https://github.com/secdev/scapy/issues/1387 so that the shell now is invisible.
If this is your issue, use the latest github version https://github.com/secdev/scapy/archive/master.zip

Related

Prevent exe file from being closed/Crash windows os if a program is closed

I'm trying to achieve something ; I created a exe file, that automatically force shutdown the computer at 11 pm.
I would like to make this script impossible to stop or crash, or even make the entire system crash if the program is closed.
How can i achieve this ?
Note :
I'm on a laptop, running windows 10. I made a python file, and i converted it in an exe file with py installer. Then i created a shortcut to that exe file that run the program with admin rights
If you mark the process as critical Windows will trigger a blue screen crash if that process is stopped/killed.
There is information about how to do this here
Note: Although it is possible to do this, it is not a good idea to do so. For example as suggested by Anders, use a Scheduled Task. Having the system crash could result in information loss, or other unintended consequences.
Create a Windows service. You can deny Administrators trying to stop/pause the service, that should slow them down a little bit.
Or since we are talking about triggering something at a specific time, you might want to use the task scheduler instead.
In any case, you will never fully lock down something like this from an Administrator since they can always take ownership and modify the ACL.

It is possible to use the CMD to send commands in the active Maya window?

I am a beginner in Maya, and I wanted to run commands in a cmd in the active window of maya to modify things in the scene, like put a sphere for example, be in python
from pymel.all import *
sphere()
or MEL
polySphere -r 1 -sx 20 -sy 20 -ax 0 1 0 -cuv 2 -ch 1;
I found the mayapi, and I found several content related to "headless" (without the GUI), but I found nothing to run in the open window yet, maybe because I don't know the terms very much. I would like it to be in python, but if you know any solution in MEL you can put it here too!
Is there any way to do this without specifying the open document path?
You have four basic options for programmatic control of maya.
Running scripts inside the script editor in Maya. This requires that you have an open GUI maya instance running and you'd either type the commands yourself, or initiate scripts by loading and executing them in the script editor. This works fine for automating repetitive tasks but requires manual intervention on your part.
You can send individual commands to Maya over a TCP connection using the maya command port This is basically like connecting to another computer over telnet: you can control the Maya sessions but you'll be communicating entirely via text. It's commonly used, for example, by people who are writing scripts in Sublime Text to test them out in Maya without switching windows
You can run a commandline-only copy of Maya using the MayaPy python interpreter that ships with Maya and the maya.standalone module, which hosts a non-GUI maya session. That lets you excute python commands in a Maya without needing the GUI at all -- it's a common tool for automation tasks.
You can pass a script argument to Maya at startup with the '-c' (for "command") flag. Maya will open and run that script. For legacy reasons the commands are only MEL, not python, but you can get around that by using the MEL command "python" along with a Python command in quotes.
All of these are useful, the right one really depends on what you need to do. For long running tasks however #3 is probably the most reliable method because it's easy to iterate on and test.

Running Python script as Executable

I have been attempting to run my python script as a service, and have followed the advice contained in several previous forum posts. However, these have not helped me thus far. Here is what I have attempted up until now:
Used an SMWinservice class that allowed me to install my Python script as a service. This solution, however, would not launch. If I would try to start it, I would receive an error message.
I have tried using NSSM with : nssm install myService pathToInterpreter PathToScript. Note, all files etc. can be found in the local directory of the PathToScript. For what its worth, I also tried using the GUI version of NSSM. When I rebooted my computer, it showed as "Paused" in task manager. I stopped it, and then tried to run it again, and I received an error. I have tried NSSM with both python.exe and pythonw.exe.
I suspect that a possible source of error is the fact that my program uses a text file as a configuration file. This configuration file has been coded as being in my local working directory. However, I wouldn't think this would be an issue with NSSM. I know for a fact that my program will completely exit, using the exit command, if the configuration file is not found.
I was thinking of doing a batch file and starting the batch file with the script and running it like that, but I prefer a service since it can monitor the process, can restart it, or windows can notify me via email if there is an issue with my service.
For completeness, I should also mention that the program runs without issue outside of a service. For the reason that the program runs as expected, I decided to not post the code, unless someone would like to see it for whatever reason.

How to open process again in linux terminal?

From my home pc using putty, I ssh'ed into a remote server, and I ran a python program that takes hours to complete, and as it runs it prints stuff. Now after a while, my internet disconnected, and I had to close and re-open putty and ssh back in. If I type 'top' I can see the python program running in the background with its PID number. Is there a command I can use to basically re-open that process and see it printing its stuff again?
Thanks
As noted, best practice is to use screen or tmux (before starting the program, so you do not need to ask this question).
But you can also attach to a running process with a debugger such as gdb (alluded to here as ddd, a wrapper for gdb), as well as with strace (see this question). That's better than nothing - but gdb and strace would not give you the program's command-line again (though this question suggests a way). At least strace could give you some clues of what the program was attempting to print.
Things to try:
nohup, or
screen

Make IPython accept commands from network socket and execute in main thread

I'm trying to hook up my Vim so I can send commands to a running IPython instance. There are scripts for this, but they are outdated. I'm trying to write a new one.
My main stumbling block right now is the proper way to make IPython listen to incoming network connections in the background (i.e. a different thread, other solutions are welcome) and executing the received commands in the main thread. Earlier scripts did not execute commands in the main thread and would crash for instance matplotlib regularly.
I see that twisted provides a ThreadedSelectReactor, but I'm at a loss as to how to use it properly with IPython.
Update
A scenario example would be:
2 Windows open, one is a terminal running IPython, one is Vim where you are editing a python script. You select a line in Vim and hit C-Enter, Vim sends the line to the IPython instance, which executes it and prints the result in the IPython terminal, just as if you had copy/pasted the line over myself.
(Matlab users know how useful this functionality can be.)
Paul Ivanov did this a few months ago, using IPython's zmq interface. It's called vim-ipython.
I get the impression that IPython is or has moved to using zmq as messaging protocol. Atleast when I am running 0.11 version zmq support is available.
Using zmq(zero mq) the whole message passing problem is very much reduced to get your Vim instance to communicate over zmq which as far as I know should not be that hard (zmq is ported to a wide variety of platforms).
Look into this blog: http://ipythonzmq.blogspot.com/
and of course: http://www.zeromq.org/

Categories