| 1 | #!/usr/bin/env python |
|---|
| 2 | # -*- coding: utf-8 -*- |
|---|
| 3 | |
|---|
| 4 | # Copyright (C) 2008 Adriano Monteiro Marques. |
|---|
| 5 | # |
|---|
| 6 | # Author: Bartosz SKOWRON <getxsick at gmail dot com> |
|---|
| 7 | # |
|---|
| 8 | # This library is free software; you can redistribute it and/or modify |
|---|
| 9 | # it under the terms of the GNU Lesser General Public License as published |
|---|
| 10 | # by the Free Software Foundation; either version 2.1 of the License, or |
|---|
| 11 | # (at your option) any later version. |
|---|
| 12 | # |
|---|
| 13 | # This library is distributed in the hope that it will be useful, but |
|---|
| 14 | # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
|---|
| 15 | # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public |
|---|
| 16 | # License for more details. |
|---|
| 17 | # |
|---|
| 18 | # You should have received a copy of the GNU Lesser General Public License |
|---|
| 19 | # along with this library; if not, write to the Free Software Foundation, |
|---|
| 20 | # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 21 | |
|---|
| 22 | import umpa.protocols._consts as const |
|---|
| 23 | |
|---|
| 24 | from umpa.protocols import * |
|---|
| 25 | from umpa.protocols._layer4 import * |
|---|
| 26 | from umpa.utils import net |
|---|
| 27 | from umpa.utils import bits |
|---|
| 28 | |
|---|
| 29 | class HPort(EnumField): |
|---|
| 30 | bits = 16 |
|---|
| 31 | auto = False |
|---|
| 32 | enumerable = { |
|---|
| 33 | "TCPMUX" : const.PORT_TCP_TCPMUX, |
|---|
| 34 | "ECHO" : const.PORT_TCP_ECHO, |
|---|
| 35 | "DISCARD" : const.PORT_TCP_DISCARD, |
|---|
| 36 | "SYSTAT" : const.PORT_TCP_SYSTAT, |
|---|
| 37 | "DAYTIME" : const.PORT_TCP_DAYTIME, |
|---|
| 38 | "NETSTAT" : const.PORT_TCP_NETSTAT, |
|---|
| 39 | "QOTD" : const.PORT_TCP_QOTD, |
|---|
| 40 | "MSP" : const.PORT_TCP_MSP, |
|---|
| 41 | "CHARGEN" : const.PORT_TCP_CHARGEN, |
|---|
| 42 | "DATA" : const.PORT_TCP_DATA, |
|---|
| 43 | "FTP" : const.PORT_TCP_FTP, |
|---|
| 44 | "SSH" : const.PORT_TCP_SSH, |
|---|
| 45 | "TELNET" : const.PORT_TCP_TELNET, |
|---|
| 46 | "SMTP" : const.PORT_TCP_SMTP, |
|---|
| 47 | "TIME" : const.PORT_TCP_TIME, |
|---|
| 48 | "NAMESERVER" : const.PORT_TCP_NAMESERVER, |
|---|
| 49 | "WHOIS" : const.PORT_TCP_WHOIS, |
|---|
| 50 | "TACACS" : const.PORT_TCP_TACACS, |
|---|
| 51 | "CK" : const.PORT_TCP_CK, |
|---|
| 52 | "DOMAIN" : const.PORT_TCP_DOMAIN, |
|---|
| 53 | "MTP" : const.PORT_TCP_MTP, |
|---|
| 54 | "DS" : const.PORT_TCP_DS, |
|---|
| 55 | "BOOTPS" : const.PORT_TCP_BOOTPS, |
|---|
| 56 | "BOOTPC" : const.PORT_TCP_BOOTPC, |
|---|
| 57 | "GOPHER" : const.PORT_TCP_GOPHER, |
|---|
| 58 | "RJE" : const.PORT_TCP_RJE, |
|---|
| 59 | "FINGER" : const.PORT_TCP_FINGER, |
|---|
| 60 | "WWW" : const.PORT_TCP_WWW, |
|---|
| 61 | "LINK" : const.PORT_TCP_LINK, |
|---|
| 62 | "KERBEROS" : const.PORT_TCP_KERBEROS, |
|---|
| 63 | "SUPDUP" : const.PORT_TCP_SUPDUP, |
|---|
| 64 | "HOSTNAMES" : const.PORT_TCP_HOSTNAMES, |
|---|
| 65 | "TSAP" : const.PORT_TCP_TSAP, |
|---|
| 66 | "NEMA" : const.PORT_TCP_NEMA, |
|---|
| 67 | "NS" : const.PORT_TCP_NS, |
|---|
| 68 | "RTELNET" : const.PORT_TCP_RTELNET, |
|---|
| 69 | "POP2" : const.PORT_TCP_POP2, |
|---|
| 70 | "POP3" : const.PORT_TCP_POP3, |
|---|
| 71 | "SUNRPC" : const.PORT_TCP_SUNRPC, |
|---|
| 72 | "AUTH" : const.PORT_TCP_AUTH, |
|---|
| 73 | "SFTP" : const.PORT_TCP_SFTP, |
|---|
| 74 | "PATH" : const.PORT_TCP_PATH, |
|---|
| 75 | "NNTP" : const.PORT_TCP_NNTP, |
|---|
| 76 | "NTP" : const.PORT_TCP_NTP, |
|---|
| 77 | "PWDGEN" : const.PORT_TCP_PWDGEN, |
|---|
| 78 | "SRV" : const.PORT_TCP_SRV, |
|---|
| 79 | "NS" : const.PORT_TCP_NS, |
|---|
| 80 | "DGM" : const.PORT_TCP_DGM, |
|---|
| 81 | "SSN" : const.PORT_TCP_SSN, |
|---|
| 82 | "IMAP2" : const.PORT_TCP_IMAP2, |
|---|
| 83 | "SNMP" : const.PORT_TCP_SNMP, |
|---|
| 84 | "TRAP" : const.PORT_TCP_TRAP, |
|---|
| 85 | "MAN" : const.PORT_TCP_MAN, |
|---|
| 86 | "AGENT" : const.PORT_TCP_AGENT, |
|---|
| 87 | "MAILQ" : const.PORT_TCP_MAILQ, |
|---|
| 88 | "XDMCP" : const.PORT_TCP_XDMCP, |
|---|
| 89 | "NEXTSTEP" : const.PORT_TCP_NEXTSTEP, |
|---|
| 90 | "BGP" : const.PORT_TCP_BGP, |
|---|
| 91 | "PROSPERO" : const.PORT_TCP_PROSPERO, |
|---|
| 92 | "IRC" : const.PORT_TCP_IRC, |
|---|
| 93 | "SMUX" : const.PORT_TCP_SMUX, |
|---|
| 94 | "RTMP" : const.PORT_TCP_RTMP, |
|---|
| 95 | "NBP" : const.PORT_TCP_NBP, |
|---|
| 96 | "ECHO" : const.PORT_TCP_ECHO, |
|---|
| 97 | "ZIS" : const.PORT_TCP_ZIS, |
|---|
| 98 | "QMTP" : const.PORT_TCP_QMTP, |
|---|
| 99 | "Z3950" : const.PORT_TCP_Z3950, |
|---|
| 100 | "IPX" : const.PORT_TCP_IPX, |
|---|
| 101 | "IMAP3" : const.PORT_TCP_IMAP3, |
|---|
| 102 | "PAWSERV" : const.PORT_TCP_PAWSERV, |
|---|
| 103 | "ZSERV" : const.PORT_TCP_ZSERV, |
|---|
| 104 | "FATSERV" : const.PORT_TCP_FATSERV, |
|---|
| 105 | "RPC2PORTMAP" : const.PORT_TCP_RPC2PORTMAP, |
|---|
| 106 | "CODAAUTH2" : const.PORT_TCP_CODAAUTH2, |
|---|
| 107 | "CLEARCASE" : const.PORT_TCP_CLEARCASE, |
|---|
| 108 | "ULISTSERV" : const.PORT_TCP_ULISTSERV, |
|---|
| 109 | "LDAP" : const.PORT_TCP_LDAP, |
|---|
| 110 | "IMSP" : const.PORT_TCP_IMSP, |
|---|
| 111 | "HTTPS" : const.PORT_TCP_HTTPS, |
|---|
| 112 | "SNPP" : const.PORT_TCP_SNPP, |
|---|
| 113 | "DS" : const.PORT_TCP_DS, |
|---|
| 114 | "KPASSWD" : const.PORT_TCP_KPASSWD, |
|---|
| 115 | "SAFT" : const.PORT_TCP_SAFT, |
|---|
| 116 | "ISAKMP" : const.PORT_TCP_ISAKMP, |
|---|
| 117 | "RTSP" : const.PORT_TCP_RTSP, |
|---|
| 118 | "NQS" : const.PORT_TCP_NQS, |
|---|
| 119 | "LOCAL" : const.PORT_TCP_LOCAL, |
|---|
| 120 | "GUI" : const.PORT_TCP_GUI, |
|---|
| 121 | "IND" : const.PORT_TCP_IND, |
|---|
| 122 | "IPP" : const.PORT_TCP_IPP, |
|---|
| 123 | "EXEC" : const.PORT_TCP_EXEC, |
|---|
| 124 | "LOGIN" : const.PORT_TCP_LOGIN, |
|---|
| 125 | "SHELL" : const.PORT_TCP_SHELL, |
|---|
| 126 | "PRINTER" : const.PORT_TCP_PRINTER, |
|---|
| 127 | "TEMPO" : const.PORT_TCP_TEMPO, |
|---|
| 128 | "COURIER" : const.PORT_TCP_COURIER, |
|---|
| 129 | "CONFERENCE" : const.PORT_TCP_CONFERENCE, |
|---|
| 130 | "NETNEWS" : const.PORT_TCP_NETNEWS, |
|---|
| 131 | "GDOMAP" : const.PORT_TCP_GDOMAP, |
|---|
| 132 | "UUCP" : const.PORT_TCP_UUCP, |
|---|
| 133 | "KLOGIN" : const.PORT_TCP_KLOGIN, |
|---|
| 134 | "KSHELL" : const.PORT_TCP_KSHELL, |
|---|
| 135 | "AFPOVERTCP" : const.PORT_TCP_AFPOVERTCP, |
|---|
| 136 | "REMOTEFS" : const.PORT_TCP_REMOTEFS, |
|---|
| 137 | "NNTPS" : const.PORT_TCP_NNTPS, |
|---|
| 138 | "SUBMISSION" : const.PORT_TCP_SUBMISSION, |
|---|
| 139 | "LDAPS" : const.PORT_TCP_LDAPS, |
|---|
| 140 | "TINC" : const.PORT_TCP_TINC, |
|---|
| 141 | "SILC" : const.PORT_TCP_SILC, |
|---|
| 142 | "ADM" : const.PORT_TCP_ADM, |
|---|
| 143 | "WEBSTER" : const.PORT_TCP_WEBSTER, |
|---|
| 144 | "RSYNC" : const.PORT_TCP_RSYNC, |
|---|
| 145 | "DATA" : const.PORT_TCP_DATA, |
|---|
| 146 | "FTPS" : const.PORT_TCP_FTPS, |
|---|
| 147 | "TELNETS" : const.PORT_TCP_TELNETS, |
|---|
| 148 | "IMAPS" : const.PORT_TCP_IMAPS, |
|---|
| 149 | "IRCS" : const.PORT_TCP_IRCS, |
|---|
| 150 | "POP3S" : const.PORT_TCP_POP3S, |
|---|
| 151 | "SOCKS" : const.PORT_TCP_SOCKS, |
|---|
| 152 | "PROOFD" : const.PORT_TCP_PROOFD, |
|---|
| 153 | "ROOTD" : const.PORT_TCP_ROOTD, |
|---|
| 154 | "OPENVPN" : const.PORT_TCP_OPENVPN, |
|---|
| 155 | "RMIREGISTRY" : const.PORT_TCP_RMIREGISTRY, |
|---|
| 156 | "KAZAA" : const.PORT_TCP_KAZAA, |
|---|
| 157 | "NESSUS" : const.PORT_TCP_NESSUS, |
|---|
| 158 | "LOTUSNOTE" : const.PORT_TCP_LOTUSNOTE, |
|---|
| 159 | "S" : const.PORT_TCP_S, |
|---|
| 160 | "M" : const.PORT_TCP_M, |
|---|
| 161 | "INGRESLOCK" : const.PORT_TCP_INGRESLOCK, |
|---|
| 162 | "NP" : const.PORT_TCP_NP, |
|---|
| 163 | "DATAMETRICS" : const.PORT_TCP_DATAMETRICS, |
|---|
| 164 | "PORT" : const.PORT_TCP_PORT, |
|---|
| 165 | "KERMIT" : const.PORT_TCP_KERMIT, |
|---|
| 166 | "L2F" : const.PORT_TCP_L2F, |
|---|
| 167 | "RADIUS" : const.PORT_TCP_RADIUS, |
|---|
| 168 | "ACCT" : const.PORT_TCP_ACCT, |
|---|
| 169 | "MSNP" : const.PORT_TCP_MSNP, |
|---|
| 170 | "STATUS" : const.PORT_TCP_STATUS, |
|---|
| 171 | "SERVER" : const.PORT_TCP_SERVER, |
|---|
| 172 | "REMOTEPING" : const.PORT_TCP_REMOTEPING, |
|---|
| 173 | "NFS" : const.PORT_TCP_NFS, |
|---|
| 174 | "SC104" : const.PORT_TCP_SC104, |
|---|
| 175 | "CVSPSERVER" : const.PORT_TCP_CVSPSERVER, |
|---|
| 176 | "VENUS" : const.PORT_TCP_VENUS, |
|---|
| 177 | "SE" : const.PORT_TCP_SE, |
|---|
| 178 | "CODASRV" : const.PORT_TCP_CODASRV, |
|---|
| 179 | "SE" : const.PORT_TCP_SE, |
|---|
| 180 | "MON" : const.PORT_TCP_MON, |
|---|
| 181 | "DICT" : const.PORT_TCP_DICT, |
|---|
| 182 | "GPSD" : const.PORT_TCP_GPSD, |
|---|
| 183 | "GDS_DB" : const.PORT_TCP_GDS_DB, |
|---|
| 184 | "ICPV2" : const.PORT_TCP_ICPV2, |
|---|
| 185 | "MYSQL" : const.PORT_TCP_MYSQL, |
|---|
| 186 | "NUT" : const.PORT_TCP_NUT, |
|---|
| 187 | "DISTCC" : const.PORT_TCP_DISTCC, |
|---|
| 188 | "DAAP" : const.PORT_TCP_DAAP, |
|---|
| 189 | "SVN" : const.PORT_TCP_SVN, |
|---|
| 190 | "SUUCP" : const.PORT_TCP_SUUCP, |
|---|
| 191 | "SYSRQD" : const.PORT_TCP_SYSRQD, |
|---|
| 192 | "IAX" : const.PORT_TCP_IAX, |
|---|
| 193 | "PORT" : const.PORT_TCP_PORT, |
|---|
| 194 | "RFE" : const.PORT_TCP_RFE, |
|---|
| 195 | "MMCC" : const.PORT_TCP_MMCC, |
|---|
| 196 | "SIP" : const.PORT_TCP_SIP, |
|---|
| 197 | "TLS" : const.PORT_TCP_TLS, |
|---|
| 198 | "AOL" : const.PORT_TCP_AOL, |
|---|
| 199 | "CLIENT" : const.PORT_TCP_CLIENT, |
|---|
| 200 | "SERVER" : const.PORT_TCP_SERVER, |
|---|
| 201 | "CFENGINE" : const.PORT_TCP_CFENGINE, |
|---|
| 202 | "MDNS" : const.PORT_TCP_MDNS, |
|---|
| 203 | "POSTGRESQL" : const.PORT_TCP_POSTGRESQL, |
|---|
| 204 | "GGZ" : const.PORT_TCP_GGZ, |
|---|
| 205 | "X11" : const.PORT_TCP_X11, |
|---|
| 206 | "1" : const.PORT_TCP_1, |
|---|
| 207 | "2" : const.PORT_TCP_2, |
|---|
| 208 | "3" : const.PORT_TCP_3, |
|---|
| 209 | "4" : const.PORT_TCP_4, |
|---|
| 210 | "5" : const.PORT_TCP_5, |
|---|
| 211 | "6" : const.PORT_TCP_6, |
|---|
| 212 | "7" : const.PORT_TCP_7, |
|---|
| 213 | "SVC" : const.PORT_TCP_SVC, |
|---|
| 214 | "RTR" : const.PORT_TCP_RTR, |
|---|
| 215 | "SGE_QMASTER" : const.PORT_TCP_SGE_QMASTER, |
|---|
| 216 | "SGE_EXECD" : const.PORT_TCP_SGE_EXECD, |
|---|
| 217 | "FILESERVER" : const.PORT_TCP_FILESERVER, |
|---|
| 218 | "CALLBACK" : const.PORT_TCP_CALLBACK, |
|---|
| 219 | "PRSERVER" : const.PORT_TCP_PRSERVER, |
|---|
| 220 | "VLSERVER" : const.PORT_TCP_VLSERVER, |
|---|
| 221 | "KASERVER" : const.PORT_TCP_KASERVER, |
|---|
| 222 | "VOLSER" : const.PORT_TCP_VOLSER, |
|---|
| 223 | "ERRORS" : const.PORT_TCP_ERRORS, |
|---|
| 224 | "BOS" : const.PORT_TCP_BOS, |
|---|
| 225 | "UPDATE" : const.PORT_TCP_UPDATE, |
|---|
| 226 | "RMTSYS" : const.PORT_TCP_RMTSYS, |
|---|
| 227 | "SERVICE" : const.PORT_TCP_SERVICE, |
|---|
| 228 | "DIR" : const.PORT_TCP_DIR, |
|---|
| 229 | "FD" : const.PORT_TCP_FD, |
|---|
| 230 | "SD" : const.PORT_TCP_SD, |
|---|
| 231 | "AMANDA" : const.PORT_TCP_AMANDA, |
|---|
| 232 | "HKP" : const.PORT_TCP_HKP, |
|---|
| 233 | "BPRD" : const.PORT_TCP_BPRD, |
|---|
| 234 | "BPDBM" : const.PORT_TCP_BPDBM, |
|---|
| 235 | "MSVC" : const.PORT_TCP_MSVC, |
|---|
| 236 | "VNETD" : const.PORT_TCP_VNETD, |
|---|
| 237 | "BPCD" : const.PORT_TCP_BPCD, |
|---|
| 238 | "VOPIED" : const.PORT_TCP_VOPIED, |
|---|
| 239 | "WNN6" : const.PORT_TCP_WNN6, |
|---|
| 240 | "KERBEROS4" : const.PORT_TCP_KERBEROS4, |
|---|
| 241 | "KERBEROS_MASTER" : const.PORT_TCP_KERBEROS_MASTER, |
|---|
| 242 | "KRB_PROP" : const.PORT_TCP_KRB_PROP, |
|---|
| 243 | "KRBUPDATE" : const.PORT_TCP_KRBUPDATE, |
|---|
| 244 | "SWAT" : const.PORT_TCP_SWAT, |
|---|
| 245 | "KPOP" : const.PORT_TCP_KPOP, |
|---|
| 246 | "KNETD" : const.PORT_TCP_KNETD, |
|---|
| 247 | "EKLOGIN" : const.PORT_TCP_EKLOGIN, |
|---|
| 248 | "KX" : const.PORT_TCP_KX, |
|---|
| 249 | "IPROP" : const.PORT_TCP_IPROP, |
|---|
| 250 | "SUPFILESRV" : const.PORT_TCP_SUPFILESRV, |
|---|
| 251 | "SUPFILEDBG" : const.PORT_TCP_SUPFILEDBG, |
|---|
| 252 | "LINUXCONF" : const.PORT_TCP_LINUXCONF, |
|---|
| 253 | "POPPASSD" : const.PORT_TCP_POPPASSD, |
|---|
| 254 | "SSMTP" : const.PORT_TCP_SSMTP, |
|---|
| 255 | "MOIRA_DB" : const.PORT_TCP_MOIRA_DB, |
|---|
| 256 | "MOIRA_UPDATE" : const.PORT_TCP_MOIRA_UPDATE, |
|---|
| 257 | "SPAMD" : const.PORT_TCP_SPAMD, |
|---|
| 258 | "OMIRR" : const.PORT_TCP_OMIRR, |
|---|
| 259 | "CUSTOMS" : const.PORT_TCP_CUSTOMS, |
|---|
| 260 | "SKKSERV" : const.PORT_TCP_SKKSERV, |
|---|
| 261 | "RMTCFG" : const.PORT_TCP_RMTCFG, |
|---|
| 262 | "WIPLD" : const.PORT_TCP_WIPLD, |
|---|
| 263 | "XTEL" : const.PORT_TCP_XTEL, |
|---|
| 264 | "XTELW" : const.PORT_TCP_XTELW, |
|---|
| 265 | "SUPPORT" : const.PORT_TCP_SUPPORT, |
|---|
| 266 | "SIEVE" : const.PORT_TCP_SIEVE, |
|---|
| 267 | "CFINGER" : const.PORT_TCP_CFINGER, |
|---|
| 268 | "NDTP" : const.PORT_TCP_NDTP, |
|---|
| 269 | "FROX" : const.PORT_TCP_FROX, |
|---|
| 270 | "NINSTALL" : const.PORT_TCP_NINSTALL, |
|---|
| 271 | "ZEBRASRV" : const.PORT_TCP_ZEBRASRV, |
|---|
| 272 | "ZEBRA" : const.PORT_TCP_ZEBRA, |
|---|
| 273 | "RIPD" : const.PORT_TCP_RIPD, |
|---|
| 274 | "RIPNGD" : const.PORT_TCP_RIPNGD, |
|---|
| 275 | "OSPFD" : const.PORT_TCP_OSPFD, |
|---|
| 276 | "BGPD" : const.PORT_TCP_BGPD, |
|---|
| 277 | "OSPF6D" : const.PORT_TCP_OSPF6D, |
|---|
| 278 | "OSPFAPI" : const.PORT_TCP_OSPFAPI, |
|---|
| 279 | "ISISD" : const.PORT_TCP_ISISD, |
|---|
| 280 | "AFBACKUP" : const.PORT_TCP_AFBACKUP, |
|---|
| 281 | "AFMBACKUP" : const.PORT_TCP_AFMBACKUP, |
|---|
| 282 | "XTELL" : const.PORT_TCP_XTELL, |
|---|
| 283 | "FAX" : const.PORT_TCP_FAX, |
|---|
| 284 | "HYLAFAX" : const.PORT_TCP_HYLAFAX, |
|---|
| 285 | "DISTMP3" : const.PORT_TCP_DISTMP3, |
|---|
| 286 | "MUNIN" : const.PORT_TCP_MUNIN, |
|---|
| 287 | "CSTATD" : const.PORT_TCP_CSTATD, |
|---|
| 288 | "SSTATD" : const.PORT_TCP_SSTATD, |
|---|
| 289 | "PCRD" : const.PORT_TCP_PCRD, |
|---|
| 290 | "NOCLOG" : const.PORT_TCP_NOCLOG, |
|---|
| 291 | "HOSTMON" : const.PORT_TCP_HOSTMON, |
|---|
| 292 | "RPLAY" : const.PORT_TCP_RPLAY, |
|---|
| 293 | "RPTP" : const.PORT_TCP_RPTP, |
|---|
| 294 | "NSCA" : const.PORT_TCP_NSCA, |
|---|
| 295 | "MRTD" : const.PORT_TCP_MRTD, |
|---|
| 296 | "BGPSIM" : const.PORT_TCP_BGPSIM, |
|---|
| 297 | "CANNA" : const.PORT_TCP_CANNA, |
|---|
| 298 | "PORT" : const.PORT_TCP_PORT, |
|---|
| 299 | "IRCD" : const.PORT_TCP_IRCD, |
|---|
| 300 | "FTP" : const.PORT_TCP_FTP, |
|---|
| 301 | "WEBCACHE" : const.PORT_TCP_WEBCACHE, |
|---|
| 302 | "TPROXY" : const.PORT_TCP_TPROXY, |
|---|
| 303 | "OMNIORB" : const.PORT_TCP_OMNIORB, |
|---|
| 304 | "DAEMON" : const.PORT_TCP_DAEMON, |
|---|
| 305 | "XINETD" : const.PORT_TCP_XINETD, |
|---|
| 306 | "GIT" : const.PORT_TCP_GIT, |
|---|
| 307 | "ZOPE" : const.PORT_TCP_ZOPE, |
|---|
| 308 | "WEBMIN" : const.PORT_TCP_WEBMIN, |
|---|
| 309 | "KAMANDA" : const.PORT_TCP_KAMANDA, |
|---|
| 310 | "AMANDAIDX" : const.PORT_TCP_AMANDAIDX, |
|---|
| 311 | "AMIDXTAPE" : const.PORT_TCP_AMIDXTAPE, |
|---|
| 312 | "SMSQP" : const.PORT_TCP_SMSQP, |
|---|
| 313 | "XPILOT" : const.PORT_TCP_XPILOT, |
|---|
| 314 | "CAD" : const.PORT_TCP_CAD, |
|---|
| 315 | "ISDNLOG" : const.PORT_TCP_ISDNLOG, |
|---|
| 316 | "VBOXD" : const.PORT_TCP_VBOXD, |
|---|
| 317 | "BINKP" : const.PORT_TCP_BINKP, |
|---|
| 318 | "ASP" : const.PORT_TCP_ASP, |
|---|
| 319 | "CSYNC2" : const.PORT_TCP_CSYNC2, |
|---|
| 320 | "DIRCPROXY" : const.PORT_TCP_DIRCPROXY, |
|---|
| 321 | "TFIDO" : const.PORT_TCP_TFIDO, |
|---|
| 322 | "FIDO" : const.PORT_TCP_FIDO, |
|---|
| 323 | } |
|---|
| 324 | |
|---|
| 325 | class HSequenceNumber(IntField): |
|---|
| 326 | """The sequence number of the first data octet in this segment (except |
|---|
| 327 | when SYN is present). |
|---|
| 328 | |
|---|
| 329 | See RFC 793 for more. |
|---|
| 330 | """ |
|---|
| 331 | bits = 32 |
|---|
| 332 | auto = True |
|---|
| 333 | def _generate_value(self): |
|---|
| 334 | # TODO: implemention real auto-filling here ;) |
|---|
| 335 | # otherwise we can simple return 0 |
|---|
| 336 | return 0 |
|---|
| 337 | |
|---|
| 338 | class HAcknowledgmentNumber(IntField): |
|---|
| 339 | """If the ACK control bit is set this field contains the value of the |
|---|
| 340 | next sequence number the sender of the segment is expecting to receive. |
|---|
| 341 | |
|---|
| 342 | See RFC 793 for more. |
|---|
| 343 | """ |
|---|
| 344 | bits = 32 |
|---|
| 345 | auto = True |
|---|
| 346 | def _generate_value(self): |
|---|
| 347 | # TODO: implemention real auto-filling here ;) |
|---|
| 348 | # otherwise we can simple return 0 |
|---|
| 349 | return 1 |
|---|
| 350 | |
|---|
| 351 | class HDataOffset(SpecialIntField): |
|---|
| 352 | """The number of 32 bit words in the TCP Header. This indicates where |
|---|
| 353 | the data begins. |
|---|
| 354 | |
|---|
| 355 | See RFC 793 for more. |
|---|
| 356 | """ |
|---|
| 357 | bits = 4 |
|---|
| 358 | auto = True |
|---|
| 359 | def _generate_value(self): |
|---|
| 360 | # returns in 32-bits units |
|---|
| 361 | return 5 + self._tmp_value / 32 # 5 is a minimum value |
|---|
| 362 | |
|---|
| 363 | class HReserved(IntField): |
|---|
| 364 | """Reserved for future use. |
|---|
| 365 | |
|---|
| 366 | See RFC 793 for more. |
|---|
| 367 | """ |
|---|
| 368 | bits = 6 |
|---|
| 369 | auto = True |
|---|
| 370 | def _generate_value(self): |
|---|
| 371 | return 0 |
|---|
| 372 | |
|---|
| 373 | class HWindow(IntField): |
|---|
| 374 | """The number of data octets beginning with the one indicated in the |
|---|
| 375 | acknowledgment field which the sender of this segment is willing to accept. |
|---|
| 376 | |
|---|
| 377 | See RFC 793 for more. |
|---|
| 378 | """ |
|---|
| 379 | bits = 16 |
|---|
| 380 | auto = True |
|---|
| 381 | def _generate_value(self): |
|---|
| 382 | # TODO: implemention real auto-filling here ;) |
|---|
| 383 | # otherwise we can simple return 0 |
|---|
| 384 | return 512 |
|---|
| 385 | |
|---|
| 386 | class HUrgentPointer(IntField): |
|---|
| 387 | """This field communicates the current value of the urgent pointer as a |
|---|
| 388 | positive offset from the sequence number in this segment. |
|---|
| 389 | |
|---|
| 390 | See RFC 793 for more. |
|---|
| 391 | """ |
|---|
| 392 | bits = 16 |
|---|
| 393 | auto = True |
|---|
| 394 | def _generate_value(self): |
|---|
| 395 | # TODO: implemention real auto-filling here ;) |
|---|
| 396 | # otherwise we can simple return 0 |
|---|
| 397 | return 0 |
|---|
| 398 | |
|---|
| 399 | class TCP(Protocol): |
|---|
| 400 | """This is Transmission Control Protocol. |
|---|
| 401 | It the most common protocol in the Internet on fourth layer |
|---|
| 402 | of the OSI model. |
|---|
| 403 | """ |
|---|
| 404 | layer = 4 # layer of the OSI |
|---|
| 405 | protocol_id = const.PROTOCOL_TCP |
|---|
| 406 | name = "TCP" |
|---|
| 407 | |
|---|
| 408 | _ordered_fields = ('source_port', 'destination_port', '_sequence_number', |
|---|
| 409 | '_acknowledgment_number', '_data_offset', '_reserved', |
|---|
| 410 | 'control_bits', '_window', '_checksum', '_urgent_pointer', |
|---|
| 411 | 'options', '_padding',) |
|---|
| 412 | |
|---|
| 413 | def __init__(self, **kw): |
|---|
| 414 | control_bits = ('urg', 'ack', 'psh', 'rst', 'syn', 'fin') |
|---|
| 415 | control_bits_predefined = dict.fromkeys(control_bits, 0) |
|---|
| 416 | |
|---|
| 417 | fields_list = [ HPort("Source Port", 0), |
|---|
| 418 | HPort("Destination Port", 0), |
|---|
| 419 | HSequenceNumber("Sequence Number"), |
|---|
| 420 | HAcknowledgmentNumber("Acknowledgment Number"), |
|---|
| 421 | HDataOffset("DataOffset"), HReserved("Reserved", 0), |
|---|
| 422 | Flags("Control Bits", control_bits, |
|---|
| 423 | **control_bits_predefined), |
|---|
| 424 | HWindow("Window"), Layer4ChecksumField("Checksum"), |
|---|
| 425 | HUrgentPointer("Urgent Pointer"), Flags("Options", ()), |
|---|
| 426 | PaddingField("Padding") ] |
|---|
| 427 | |
|---|
| 428 | # we call super.__init__ after prepared necessary data |
|---|
| 429 | super(TCP, self).__init__(fields_list, **kw) |
|---|
| 430 | |
|---|
| 431 | # set __doc__ for fields - it's important if you want to get hints |
|---|
| 432 | # in some frontends. E.g. Umit Project provides one... |
|---|
| 433 | self._get_field('source_port').set_doc("The source port number. \ |
|---|
| 434 | See RFC 793 for more.") |
|---|
| 435 | self._get_field('destination_port').set_doc("The destination port \ |
|---|
| 436 | number. See RFC 793 for more.") |
|---|
| 437 | self._get_field('control_bits').set_doc("URG, ACK, PSH, RST, SYN, FIN \ |
|---|
| 438 | flags. See RFC 793 for more.") |
|---|
| 439 | self._get_field('_checksum').set_doc("Checksum of Pseudo Header, TCP \ |
|---|
| 440 | header and data. See RFC 793 for more.") |
|---|
| 441 | self._get_field('options').set_doc("Options may occupy space at the \ |
|---|
| 442 | end of the TCP header and are a multiple of 8 bits in length. See RFC 793 \ |
|---|
| 443 | for more.") |
|---|
| 444 | self._get_field('_padding').set_doc("The TCP header padding is used \ |
|---|
| 445 | to ensure that the TCP header ends and data begins on a 32 bit boundary. \ |
|---|
| 446 | See RFC 793 for more.") |
|---|
| 447 | |
|---|
| 448 | def _pre_raw(self, raw_value, bit, protocol_container, protocol_bits): |
|---|
| 449 | # Padding |
|---|
| 450 | self._get_field('_padding')._tmp_value = \ |
|---|
| 451 | self._get_field('options').bits |
|---|
| 452 | |
|---|
| 453 | # Data Offset |
|---|
| 454 | self._get_field('_data_offset')._tmp_value = \ |
|---|
| 455 | self._get_field('options').bits + self._get_field('_padding').bits |
|---|
| 456 | |
|---|
| 457 | return raw_value, bit |
|---|
| 458 | |
|---|
| 459 | def _post_raw(self, raw_value, bit, protocol_container, protocol_bits): |
|---|
| 460 | # rev_offset it the offset from the right side |
|---|
| 461 | cksum_rev_offset = bit - self.get_offset('_checksum') - \ |
|---|
| 462 | self._get_field('_checksum').bits |
|---|
| 463 | # checking if user not defined his own value of checksum |
|---|
| 464 | if bits.get_bits(raw_value, self._get_field('_checksum').bits, |
|---|
| 465 | cksum_rev_offset, rev_offset=True) == 0: |
|---|
| 466 | # Payload |
|---|
| 467 | if self.payload: |
|---|
| 468 | cksum = self.payload.__dict__['__raw_value'] |
|---|
| 469 | else: |
|---|
| 470 | cksum = 0 |
|---|
| 471 | offset = protocol_bits |
|---|
| 472 | |
|---|
| 473 | # TCP Header |
|---|
| 474 | cksum |= raw_value << offset |
|---|
| 475 | offset += bit |
|---|
| 476 | |
|---|
| 477 | # Pseudo Header |
|---|
| 478 | # |
|---|
| 479 | # TCP header length...converted to bits unit |
|---|
| 480 | total_length = self._get_field('_data_offset').fillout()*32 |
|---|
| 481 | # add payload |
|---|
| 482 | total_length += protocol_bits |
|---|
| 483 | # conversion to bytes unit |
|---|
| 484 | total_length /= 8 |
|---|
| 485 | |
|---|
| 486 | # create pseudo header object |
|---|
| 487 | pheader = PseudoHeader(self.protocol_id, total_length) |
|---|
| 488 | # generate raw value of it |
|---|
| 489 | pheader_raw = pheader._get_raw(protocol_container, |
|---|
| 490 | protocol_bits)[0] |
|---|
| 491 | # added pseudo header bits to cksum value |
|---|
| 492 | cksum |= pheader_raw << offset |
|---|
| 493 | |
|---|
| 494 | # finally, calcute and apply checksum |
|---|
| 495 | raw_cksum = net.in_cksum(cksum) |
|---|
| 496 | raw_value |= raw_cksum << cksum_rev_offset |
|---|
| 497 | |
|---|
| 498 | return raw_value, bit |
|---|
| 499 | |
|---|
| 500 | protocols = [ TCP, ] |
|---|