Friday, 15 March 2013

Java server application to emulate Mysql -



Java server application to emulate Mysql -

i have client java application connects on jdbc mysql server. replace mysql prototype java server application. application should receive , send bytes client on socket, client „thinks“ communicates mysql. have done wireshark capture , got hex values. emulate, send same server greeting bytes server client client starts send sql commands server. capture wireshark when mysql responds java client. mysql greeting server response:

0000 00 19 99 5d 6f 53 00 12 00 85 4c ce 08 00 45 00 ...]os....l...e. 0010 00 60 3e 49 40 00 3f 06 e8 84 8d 1d 7d 35 8d 1d .`>i@.?.....}5.. 0020 7d 5a 0c ea ef dc 14 56 67 8e 17 b8 70 a8 50 18 }z.....vg...p.p. 0030 00 73 af 71 00 00 34 00 00 00 0a 35 2e 31 2e 36 .s.q..4....5.1.6 0040 31 00 74 00 00 00 4a 29 2e 4b 6d 66 38 22 00 ff 1.t...j).kmf8".. 0050 f7 08 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 0060 00 3f 56 72 5c 58 23 44 6d 76 2c 73 22 00 .?vr\x#dmv,s".

and wireshark capture, when have java server replacement mysql. java server application emulates mysql server greeting message sends much bytes reason:

0000 00 19 99 5d 6f 53 00 12 00 85 4c ce 08 00 45 00 ...]os....l...e. 0010 00 96 8d 8d 40 00 3f 06 99 0a 8d 1d 7d 35 8d 1d ....@.?.....}5.. 0020 7d 5a 0c ea fd 4b a8 2d 3f 6d 96 b3 42 b3 50 18 }z...k.-?m..b.p. 0030 00 73 85 d7 00 00 00 19 99 5d 6f 53 00 12 00 85 .s.......]os.... 0040 4c ce 08 00 45 00 00 60 3e 49 40 00 3f 06 e8 84 l...e..`>i@.?... 0050 8d 1d 7d 35 8d 1d 7d 5a 0c ea ef dc 14 56 67 8e ..}5..}z.....vg. 0060 17 b8 70 a8 50 18 00 73 af 71 00 00 34 00 00 00 ..p.p..s.q..4... 0070 0a 35 2e 31 2e 36 31 00 74 00 00 00 4a 29 2e 4b .5.1.61.t...j).k 0080 6d 66 38 22 00 ff f7 08 02 00 00 00 00 00 00 00 mf8"............ 0090 00 00 00 00 00 00 00 3f 56 72 5c 58 23 44 6d 76 .......?vr\x#dmv 00a0 2c 73 22 00 ,s".

how can send same bytes captured wireshark java server on socket java client? here java code utilize on server side:

import java.io.*; public class server { /** * */ public void run() { seek { int serverport = 3306; serversocket serversocket = new serversocket(serverport); serversocket.setsotimeout(10000); while(true) { system.out.println("waiting client on port " + serversocket.getlocalport() + "..."); socket server = serversocket.accept(); system.out.println("just connected " + server.getremotesocketaddress()); byte[] clientmessage = hexstringtobytearray("0019995d6f53001200854cce0800450000603e4940003f06e8848d1d7d358d1d7d5a0ceaefdc1456678e17b870a850180073af710000340000000a352e312e363100740000004a292e4b6d66382200fff7080200000000000000000000000000003f56725c5823446d762c732200"); bufferedoutputstream bos = new bufferedoutputstream(server.getoutputstream()); bos.write(clientmessage); bos.flush(); system.out.println("data sent back"); } } catch(unknownhostexception ex) { ex.printstacktrace(); } catch(ioexception e){ e.printstacktrace(); } } private byte[] hexstringtobytearray(string string) { int len = string.length(); byte[] info = new byte[len / 2]; (int = 0; < len; += 2) { data[i / 2] = (byte) ((character.digit(string.charat(i), 16) << 4) + character.digit(string.charat(i+1), 16)); } homecoming data; } public static void main(string[] args) { server srv = new server(); srv.run(); } }

java mysql sockets jdbc wireshark

No comments:

Post a Comment