Quoteconnection from 127.0.0.1:65288
mitm server received data: ☺ ☺↕4é¨
Use of uninitialized value $size in concatenation (.) or string at mitm.pl line 52.
mitm client sent data of length ( ☺ ☺↕4é¨ )
mitm client received response:
mitm server is sending data to real client
mitm server has send data to real client
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
use IO::Socket::INET;
use warnings;
use strict;
# auto-flush on socket
$| = 1;
# creating a listening socket
# => Wir sind der Server fuer den Anwender
my $socket_server = new IO::Socket::INET (
LocalHost => '0.0.0.0',
LocalPort => '9000',
Proto => 'tcp',
Listen => 5,
Reuse => 1
);
die "cannot create socket $!\n" unless $socket_server;
print "server waiting for client connection on port 9200\n";
# create a connecting socket
# => Wir sind der Client fuer das Endgeraet
my $socket_client = new IO::Socket::INET (
PeerHost => 'destination-srv',
PeerPort => '9000',
Proto => 'tcp',
);
die "cannot connect to the server $!\n" unless $socket_client;
print "client-part connected to the server (endpoint)\n";
while(1)
{
print "\n\n\n";
# waiting for a new client connection
my $client_socket = $socket_server->accept();
# get information about a newly connected client
my $client_address = $client_socket->peerhost();
my $client_port = $client_socket->peerport();
print "connection from $client_address:$client_port\n";
# read up to 1024 characters from the connected client
my $data = "";
$client_socket->recv($data, 1024);
print "mitm server received data: $data\n";
#####################
### MITM-PART ###
#####################
my $size = $socket_client->send($data);
print "mitm client sent data of length ".$size." (".$data.")\n";
# notify server that request has been sent
shutdown($socket_client, 1);
# receive a response of up to 1024 characters from server
my $response = "";
$socket_client->recv($response, 1024);
print "mitm client received response: $response\n";
#####################
### MITM-PART ###
#####################
# write response data to the connected client
print "mitm server is sending data to real client\n";
$client_socket->send($response);
print "mitm server has send data to real client\n";
# notify client that response has been sent
shutdown($client_socket, 1);
}
$socket_client->close();
$socket_server->close();
Quotemitm server received data: ☺ ☺↕4é¨
Quotemitm client sent data of length ( ☺ ☺↕4é¨ )
1
2
my $size = $socket_client->send($data);
print "mitm client sent data of length ".$size." (".$data.")\n";
QuoteQuelle: http://search.cpan.org/~xsawyerx/perl-5.26.0/pod/p...send SOCKET,MSG,FLAGS,TO
send SOCKET,MSG,FLAGS
Sends a message on a socket. Attempts to send the scalar MSG to the SOCKET filehandle. Takes the same flags as the system call of the same name. On unconnected sockets, you must specify a destination to send to, in which case it does a sendto(2) syscall. Returns the number of characters sent, or the undefined value on error. The sendmsg(2) syscall is currently unimplemented. See "UDP: Message Passing" in perlipc for examples.
Note the characters: depending on the status of the socket, either (8-bit) bytes or characters are sent. By default all sockets operate on bytes, but for example if the socket has been changed using binmode to operate with the :encoding(UTF-8) I/O layer (see open, or the open pragma), the I/O will operate on UTF-8 encoded Unicode characters, not bytes. Similarly for the :encoding layer: in that case pretty much any characters can be sent.
1 2 3 4 5 6 7
# $server ist eine Instanz IO::Socket::INET while ( my $client = $server->accept ){ # Daten vom client aus socket lesen my $data = <$client>; # sende daten an client zurück print $lient, $data; }
QuoteDas habe ich gemacht.Lies bitte meine Posts.
QuoteWas netstat macht ist mir klar und da der Client eine Verbindung zum Server aufbauen konnte fand ich den Auszug von netstat überflüssig.Das Kommando netstat zeigt Dir doch welche Anwendung an welchem Port lauscht, so siehst Du auch welche Ports Du für Deinen Server einstellen kannst.
Ich habe Dich 2x gefragt was netstat bei Dir ausgibt und keine Anwort bekommen!
QuoteDa sagt die Doku etwas anderes:Des Weiteren, Was verstehst Du unter Hexdaten? Ein Socket kennt weder Zeichen noch deren Bedeutung, in einem Socket gibt es weder Binärdaten nocht Text sondern nur Bytesequenzen.
QuoteBisher hatte ich immer binäre Daten geschrieben.By default all sockets operate on bytes, but for example if the socket has been changed using binmode to operate with the :encoding(UTF-8) I/O layer (see open, or the open pragma), the I/O will operate on UTF-8 encoded Unicode characters, not bytes
QuoteVermutlich ist genau das mein Problem.Es ist jedoch möglich, dass deine Funktion die aus dem Socket liest zwischen Textmodus und binmode unterscheidet.
QuoteIn der Doku, die ich bisher gefunden hatte, konnte ich dazu nichts finden.Also Doku lesen bitte und dann findest Du auch den Fehler.
QuoteIn der Doku, die ich bisher gefunden hatte, konnte ich dazu nichts finden.