Skip to content

Commit

Permalink
Merge pull request #112 from GoSecure/add_connection_time
Browse files Browse the repository at this point in the history
Add a connection time log statement upon client disconnection
  • Loading branch information
Pourliver authored Jun 10, 2019
2 parents 139a505 + 4ea9ab2 commit cb6f495
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions pyrdp/mitm/TCPMITM.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Copyright (C) 2019 GoSecure Inc.
# Licensed under the GPLv3 or later.
#

import time
from logging import LoggerAdapter
from typing import Coroutine

Expand All @@ -28,6 +28,9 @@ def __init__(self, client: TwistedTCPLayer, server: TwistedTCPLayer, attacker: T
:param serverConnector: coroutine that connects to the server side, closed when the client disconnects
"""

self.connectionTime = 0
# To keep track of the duration of the TCP connection.

self.client = client
self.server = server
self.attacker = attacker
Expand Down Expand Up @@ -63,7 +66,7 @@ def onClientConnection(self):
"""
Log the fact that a new client has connected.
"""

self.connectionTime = time.time()
self.log.info("New client connected")

def onClientDisconnection(self, reason):
Expand All @@ -72,8 +75,11 @@ def onClientDisconnection(self, reason):
:param reason: reason for disconnection
"""

self.connectionTime = time.time() - self.connectionTime

self.recordConnectionClose()
self.log.info("Client connection closed. %(reason)s", {"reason": reason.value})
self.log.info("Client connection time: %(connectionTime)s secs", {"connectionTime": self.connectionTime})
self.serverConnector.close()
self.server.disconnect(True)

Expand Down

0 comments on commit cb6f495

Please sign in to comment.