I'm working in order to create a legitimate client by uscing scapy for a MQTT network. I implemented the 3-way handshake and a possible connection with the MQTT broker (the broker is fully working, i tested it with another client). Here my code:
from scapy.contrib.mqtt import *
from scapy.all import send, sendp, IP, TCP, Ether, sr, sr1
seq = 12345
src='192.168.1.90'
dst='192.168.1.91'
sport = 1040
dport=1883
pkt=IP(src=src, dst=dst)
SYN=pkt/TCP(sport=sport, dport=dport, flags="S")
SYNACK=sr1(SYN)
ACK=pkt/TCP(sport=sport, dport=dport, flags="A", seq=SYNACK.ack, ack=SYNACK.seq + 1)
send(ACK)
payload_packet = TCP(sport=sport, dport=dport, flags='A', seq=ACK.ack, ack=ACK.seq + 1)
mqtt_pkt = MQTTConnect(clientId='my_client_id')
reply, error = sr(pkt/payload_packet/mqtt_pkt, multi=1, timeout=1)
for r in reply:
r[0].show2()
r[1].show2()
This code is not able to connect the client to the MQTT broker since the software send a RST before an ACK packet. Please see the image below.
Wireshark flow:
Could you please help me? Thanks in advance