(self, conn, blob)
| 195 | |
| 196 | |
| 197 | def blob_handler(self, conn, blob): |
| 198 | try: |
| 199 | info = self.conns[conn.addr] |
| 200 | except KeyError: |
| 201 | # connection was not initialized correctly |
| 202 | # set the blob to hidden and move on |
| 203 | blob.hidden = True |
| 204 | return |
| 205 | |
| 206 | if info['mode'] == DATA_CONN: |
| 207 | return conn, blob |
| 208 | |
| 209 | try: |
| 210 | data = blob.data |
| 211 | data = data.decode('ascii') |
| 212 | except UnicodeDecodeError as e: |
| 213 | # Could not convert command data to readable ASCII |
| 214 | blob.hidden = True |
| 215 | return |
| 216 | |
| 217 | if blob.direction == 'cs': |
| 218 | # client-to-server: try and get the command issued |
| 219 | if ' ' not in data.rstrip(): |
| 220 | command = data.rstrip() |
| 221 | param = '' |
| 222 | else: |
| 223 | command, param = data.rstrip().split(' ', 1) |
| 224 | command = command.upper() |
| 225 | info['lastcommand'] = command |
| 226 | |
| 227 | if command == 'USER': |
| 228 | info['user'] = param |
| 229 | |
| 230 | elif command == 'PASS': |
| 231 | info['pass'] = param |
| 232 | |
| 233 | elif command == 'CWD': |
| 234 | info['path'].append(param) |
| 235 | |
| 236 | elif command == 'PASV' or command == 'EPSV': |
| 237 | if self.dump: |
| 238 | # Temporarily store the pair of IP addresses |
| 239 | # to open up the BPF filter until blob_handler processes |
| 240 | # the response with the full IP/Port information. |
| 241 | # Note: Due to the way blob processing works, we don't |
| 242 | # get this information until after the data channel is |
| 243 | # established. |
| 244 | info['tempippair'] = tuple( |
| 245 | sorted((conn.clientip, conn.serverip)) |
| 246 | ) |
| 247 | self.__update_bpf() |
| 248 | |
| 249 | # For file transfers (including LIST), store tuple |
| 250 | # (Direction, Path, Filename) in info['file'] |
| 251 | elif command == 'LIST': |
| 252 | if param == '': |
| 253 | info['file'] = ( |
| 254 | 'RETR', os.path.normpath(os.path.join(*info['path'])) |
nothing calls this directly
no test coverage detected