Sniffing at two sockets

Discussion in 'Python' started by n00m, Apr 26, 2005.

  1. n00m

    n00m Guest

    In a simple VB script I open ADODB.Connection and start sending
    some very simple T-SQL commands to a MS SQL Server. Like this:

    ------------------------------------------------------------

    Set cn = CreateObject("ADODB.Connection")
    cn.Open _
    "Provider=sqloledb;Data Source=127.0.0.1,1434;" & _
    "Network Library=DBMSSOCN;Initial Catalog=pubs;" & _
    "User ID=qwe;Password=asdasd;"

    cn.Execute _
    "select 'XXXXXXXXXXXX';" & _
    "waitfor delay '00:00:03'; raiserror ('AAA',10,1) with nowait;" & _
    "waitfor delay '00:00:03'; raiserror ('BBB',10,1) with nowait;" & _
    "waitfor delay '00:00:03'; raiserror ('CCC',10,1) with nowait;" & _
    "waitfor delay '00:00:03'; select 'YYYYYYYYYYYY';"

    ------------------------------------------------------------
    BUT I do it (sending to\fro data) via two sockets opened in a python
    code. Note: in above connection string I direct VB script to port 1434,
    BUT the SQL Server listens to its default port = 1433.
    Here my python code:
    ------------------------------------------------------------

    import socket
    host, port = '127.0.0.1', 1434
    s1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s2.connect((host, 1433))
    s1.bind((host, port))
    s1.listen(1)
    cn, addr = s1.accept()
    while 1:
    data = cn.recv(4096)
    if not data: break
    s2.send(data)
    print 'VB_SCRIPT:', data
    data = s2.recv(4096)
    if not data: break
    cn.send(data)
    print 'SQL_SERVER:', data
    cn.close()
    s1.close()
    s2.close()

    ------------------------------------------------------------
    And in the 0-approximation everything works just fine! I can
    see printed intercepted requests\replies from VBS\SQLServer.
    BUT alas it does not work EXACTLY as it works if the VB script
    "connects" DIRECTLY to the "true" SQL Server's port = 1433.

    After receiving the first error_message 'AAA' the VBS should
    immediately issue something like 'Ready to receive next packet'
    (in my newbish understanding), BUT instead it gets frozen till
    its CommandTimeout times out and only then it wakes up, issues
    a final request and gets ALL data that SQL Server "accumulated"
    for the client's side; namely, error_messages 'BBB' and 'CCC'
    and result of "select 'YYYYYYYYYYYY'".

    ANY IDEAS WHY IT WORKS NOT QUITE CORRECTLY WILL BE GREATLY
    APPRECIATED!!!
    n00m, Apr 26, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lauchlan M
    Replies:
    2
    Views:
    418
    John Saunders
    Aug 17, 2003
  2. CW
    Replies:
    1
    Views:
    506
    John Saunders
    May 3, 2004
  3. Fabiano Sidler
    Replies:
    0
    Views:
    356
    Fabiano Sidler
    Jun 21, 2004
  4. David Pratt

    Sniffing Text Files

    David Pratt, Sep 23, 2005, in forum: Python
    Replies:
    2
    Views:
    297
    Steven D'Aprano
    Sep 23, 2005
  5. Filipe Manana

    Raw Sockets for packet sniffing

    Filipe Manana, Jul 14, 2008, in forum: Ruby
    Replies:
    0
    Views:
    207
    Filipe Manana
    Jul 14, 2008
Loading...

Share This Page