sendpfast isn't working: How to include tcprelay - scapy

I want to send traffic using scapy at faster rates. I am keeping the scapy and tcprelay files in my local folder. how should I include the tcprelay ?
[amaragra#guestshell ~]$ ls -l
total 8
drwxr-xr-x 8 root root 1024 Jan 26 07:14 scapy
drwxr-xr-x 11 root root 1024 Jan 26 07:31 tcpreplay
[amaragra#guestshell ~]$
[amaragra#guestshell ~]$ python
import sys
sys.path.insert(0, "scapy")
from scapy.all import *
pkt = Ether(src="00:00:00:00:00:01", dst="00:00:00:00:00:02")/IP(src="10.1.1.1", dst="10.1.1.2")/UDP(sport=5001, dport=5002)/Raw(RandString(size=1460))
sendpfast(pkt, pps=1000, loop=10000, parse_results=1)
ERROR: Could not execute tcpreplay, is it installed?
Traceback (most recent call last):
File "scapy/scapy/sendrecv.py", line 435, in sendpfast stderr=subprocess.PIPE)
File "/usr/lib64/python2.7/subprocess.py", line 711, in __init__
File "/usr/lib64/python2.7/subprocess.py", line 1327, in _execute_child
OSError: [Errno 2] No such file or directory
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "scapy/scapy/sendrecv.py", line 449, in sendpfast os.unlink(f)
OSError: [Errno 2] No such file or directory: '/tmp/scapy8arQdz'
>>>

Check version of tcpreplay, try to reinstall. It help in my case.
>>> sendpfast(pkt, mbps=1000, loop=50000)
ERROR: while trying to exec [tcpreplay]: [Errno 2] No such file or directory

You can set
from scapy.config import conf
conf.prog.tcpreplay = "/path/to/tcpreplay"
to set the path to the executable scapy will use. You could also likely just add tcpreplay's folder to your PATH.

Related

Raspberry Pi OS - at command does nothing

I have a Pi 3B+ with Pi OS (PRETTY_NAME="Raspbian GNU/Linux 10 (buster)")
I want to run a script at a certain time, using at command.
For testing purposes i have made a test1.sh, to open Chromium browser using pyautogui.
This file is located in /home/pi/test1.sh and contains the following:
#!/usr/bin/python3
import pyautogui
pyautogui.click(67, 20) #click Chromium icon
This .sh executes fine when clicked in the GUI and also when I run it typing ./test1.sh in the Terminal.
Trying to use at command does not work and yields the following:
pi#raspberrypi:~ $ at 11:50
warning: commands will be executed using /bin/sh
at> ./test1.sh
at> < EOT> (Here is where I type ctrl+D)
job 11 at Fri Nov 5 11:50:00 2021
At the specified time, nothing happens. I know it must be something I am doing wrong, but for the life of me I can not figure out what it is. Help?
Edit:
the first / in the shebang was missing in the post, but not in the file.
atq returns nothing
ps ax returns text below (cut for brevity)
PID TTY STAT TIME COMMAND
1 ? Ss 0:05 /sbin/init splash
2 ? S 0:00 [kthreadd]
3 ? I< 0:00 [rcu_gp]
date returns accurate date and time
cat /var/mail/pi returns the following:
Subject: Output from your job 11
To: pi#raspberrypi
Message-Id: <E1miwnI-0000tR-83#raspberrypi>
From: pi#raspberrypi
Date: Fri, 05 Nov 2021 11:50:00 +0100
sh: 49: ./test1.sh: not found
From pi#raspberrypi Fri Nov 05 12:05:00 2021
Return-path: <pi#raspberrypi>
Envelope-to: pi#raspberrypi
Delivery-date: Fri, 05 Nov 2021 12:05:00 +0100
Received: from pi by raspberrypi with local (Exim 4.92)
(envelope-from <pi#raspberrypi>)
id 1mix1o-0000xA-KG
for pi#raspberrypi; Fri, 05 Nov 2021 12:05:00 +0100
This suggests that the file is not there, but when I type ls it is clearly shown.
Using the full path /home/pi/test1.sh also returns nothing but the mail received states the following:
Subject: Output from your job 13
To: pi#raspberrypi
Message-Id: <E1mjHmv-0000NT-4B#raspberrypi>
From: pi#raspberrypi
Date: Sat, 06 Nov 2021 10:15:01 +0100
Traceback (most recent call last):
File "/home/pi/test1.sh", line 3, in <module>
import pyautogui
File "/home/pi/.local/lib/python3.7/site-packages/pyautogui/__init__.py", line 249, in <module>
import mouseinfo
File "/home/pi/.local/lib/python3.7/site-packages/mouseinfo/__init__.py", line 223, in <module>
_display = Display(os.environ['DISPLAY'])
File "/usr/lib/python3.7/os.py", line 678, in __getitem__
raise KeyError(key) from None
KeyError: 'DISPLAY'
As pointed out by #linuxfan in the comments:
The DISPLAY variable is not set.
problem was fixed by doing the following:
pi#raspberrypi:~ $ at now + 1 minute
warning: commands will be executed using /bin/sh
at> export DISPLAY=:0.0
at> /home/pi/test1.sh
at> <EOT>
job 17 at Sun Nov 7 10:55:00 2021

Having problems with _path in python script with "Module Not Found" even though they are present

I am using Python3.8 on windows10, with Spyder4 and busy working through examples from DarwinEx about algo trading and how they do it but I've run into a basic issue. When I try and run the file in IPython it does not see the other files in the same directory that it is supposed to import. I know I am doing something wrong just not sure what.
Have tried to hard code the path as you see in the image below and also tried another way as per a post her on SO.
I need to run the 'coin_flip_traders_v1.0.py' which then executes the errors.
Here it shows all files in the same directory.
In[65]: pwd
Out[65]: 'C:\\DNNTrain\\Coursera\\darwinex'
ls
Volume in drive C has no label.
Volume Serial Number is 544C-EAA4
Directory of C:\DNNTrain\Coursera\darwinex
24/01/2020 11:24 <DIR> .
24/01/2020 11:24 <DIR> ..
23/01/2020 23:43 <DIR> __pycache__
24/01/2020 11:24 9,700 coin_flip_traders_v1.0.py
24/01/2020 10:14 <DIR> DarwinexLabs-master
24/01/2020 09:47 5,101 DWX_HISTORY_IO_v2_0_1_RC8.py
23/01/2020 22:25 26,718 DWX_ZeroMQ_Connector_v2_0_1_RC8.py
24/01/2020 09:47 35,491 DWX_ZeroMQ_Server_v2.0.1_RC8.mq4
24/01/2020 09:47 2,195 DWX_ZMQ_Execution.py
24/01/2020 09:47 1,928 DWX_ZMQ_Reporting.py
24/01/2020 11:23 2,219 DWZ_ZMQ_Strategy.py
24/01/2020 11:10 <DIR> EXAMPLES
7 File(s) 83,352 bytes
5 Dir(s) 116,616,744,960 bytes free
Tis is the part in the code that it calls.
import os
#_path = 'C:\\DNNTrain\\Coursera\\darwinex\\' # Tried this with no luck
_path = './' # Also not working
os.chdir(_path)
#from EXAMPLES.TEMPLATE.STRATEGIES.BASE.DWX_ZMQ_Strategy import DWX_ZMQ_Strategy
from DWX_ZMQ_Strategy import DWX_ZMQ_Strategy
Here is the command and output I get.
Traceback (most recent call last):
File "C:\DNNTrain\Coursera\darwinex\coin_flip_traders_v1.0.py", line 47, in <module>
from DWX_ZMQ_Strategy import DWX_ZMQ_Strategy
ModuleNotFoundError: No module named 'DWX_ZMQ_Strategy'
Appreciate the help.
Just before hanging myself I saw that I copied all the files into the same directory and provided the _path correctly, but I never thought that they would have a typo in their file name. In the ls above you can see it is "DWZ...." instead it should be "DWX..." as per the call from the script and all the other files.
Guess Z and X are indeed very close to each other.
Lesson learned: Analysis paralysis - couldn't think that it would be so simple.

How to work around Python 3 maximum string size?

On a 64 bit Python build with a sys.maxsize of 9223372036854775807 the
interpreter nevertheless throws a MemoryError if I allocate a string of more
than INT_MAX - 512 MiB chars:
$ python3
#Python 3.6.6 (default, Jul 19 2018, 14:25:17)
[GCC 8.1.1 20180712 (Red Hat 8.1.1-5)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> s = "*" * 2684354560
>>> s = "*" * 2684354561
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
MemoryError
(The limit is the same for bytes whose element type is definitely 8 bits.)
There is plenty of free memory and swap so I am certain the system is not
hitting any physical limits.
What is happening here and how can I increase this cap?
Resolution: turns out to be the
data segment size limit
$ ulimit -d
4194304
For some reason, these 4294967296 B translate to a 2684354560 B per-allocation
cap in Python.
Setting this value to unlimited removes the cap. This can be done externally
by the parent process (e. g. ulimit -d unlimited from the shell) or
in Python itself using the
wrapper library for resource.h:
resource.setrlimit (resource.RLIMIT_DATA,
(resource.RLIM_INFINITY
,resource.RLIM_INFINITY))
Apparently on more
recent kernels (4.7 and later) RLIMIT_DATA affects anonymous mappings too which
explains both the observed failure of large-ish allocations and my being
surprised.

Failed opening the RDB file ... Read-only file system

I'm trying to perform a save or bgsave on my redis instance to run through the backup/restore process. I'm getting errors when I try to save however:
532:M 28 Jun 23:58:30.396 # Failed opening the RDB file backup.rdb (in server root dir /var/lib/redis) for saving: Read-only file system
Permissions on the /var/lib/redis folder:
$#/var/lib$ ls -artl | grep redis
drwxrwxrwx 3 redis redis 4096 Jun 28 23:58 redis
Permissions on the /var/lib folder:
$#/var$ ls -artl | grep lib
drwxrwxrwx 31 root root 4096 Jun 28 23:44 lib
Permissions on the /var folder:
$#/$ ls -artl | grep var
drwxrwxrwx 11 root root 4096 Jul 18 2016 var
Redis CLI output for config get dir:
1) "dir"
2) "/var/lib/redis"
Redis CLI output for config get dbfilename:
1) "dbfilename"
2) "backup.rdb"
Error from redis:
532:M 28 Jun 23:58:30.396 # Failed opening the RDB file backup.rdb (in server root dir /var/lib/redis) for saving: Read-only file system
Any help would be much appreciated!
You need to add the following to your /etc/systemd/system/redis-server unit file:
ReadWriteDirectories=-/var/lib/redis
Note that /var/lib/redis is the default, but if in your /etc/redis/redis.conf you set a different dir config option, you will need to set ReadWriteDirectories to that.
Error says Read-only file system
So, check the mounting (/ or /var) of file system, if it is read only, remount the FS with rw mode(read and write mode)
Take backup of important data before mounting.

Can't establish more than about 1024 HTTP connections

I'm curious what limit I'm raised? I have the next code:
import httplib, resource, socket, traceback
print("NOFILE: %s" % str(resource.getrlimit(resource.RLIMIT_NOFILE)))
socket.setdefaulttimeout(100000)
conns = []
for _ in xrange(10000000):
con = httplib.HTTPConnection('ya.ru') # or 93.158.134.3
try:
con.connect()
conns.append(con)
except:
print("Total connections: %s\n" % len(conns))
print(traceback.format_exc())
break
input("Press any key to exit...")
When HTTPConnection uses a host name, I get the next output:
NOFILE: (2560, 9223372036854775807)
Total connections: 1019
Traceback (most recent call last):
File "test.py", line 13, in <module>
con.connect()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 772, in connect
self.timeout, self.source_address)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 571, in create_connection
raise err
error: [Errno 65] No route to host
And when I use the direct IP address:
NOFILE: (2560, 9223372036854775807)
Total connections: 1021
Traceback (most recent call last):
File "test.py", line 13, in <module>
con.connect()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 772, in connect
self.timeout, self.source_address)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 571, in create_connection
raise err
error: [Errno 36] Operation now in progress
It looks like pretty the same point of failure because 1019, 1021 and 1024 are very close values. I think 1024 is a some limit within my OS.
uname -a
Darwin hackmachine 13.3.0 Darwin Kernel Version 13.3.0: Tue Jun 3 21:27:35 PDT 2014; root:xnu-2422.110.17~1/RELEASE_X86_64 x86_64
ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
file size (blocks, -f) unlimited
max locked memory (kbytes, -l) unlimited
max memory size (kbytes, -m) unlimited
open files (-n) 2560
pipe size (512 bytes, -p) 1
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 709
virtual memory (kbytes, -v) unlimited
So, my questions are:
What's the limitation I encountered?
What are explanations for the error
messages? They don't look very self-explaining.
UPD: Tried the same thing on Debian 7. ulimit -n <limit> works as expected and I can establish as much connections as is set by ulimit. So, it looks like an OS X specific problem.

Resources