Classification: TOP SECRET//COMINT//ORCON//REL TO USA, FVEY//20291123 KEYSCORE # X-KEYSCORE Application IDs xkeyscore@nsa Classification: TOP SECRET//COMINT//ORCON//REL TO USA, FVEY//20291123 --- Classification: TOP SECRET//COMINT//ORCON//REL TO USA, FVEY//20291123 ## Basic Syntax **Syntax:** * Very C-like. `function('name', level, ) = 'search terms and pattern';` Two valid search functions appid and fingerprint: * `appid('chat/icq', 8.5, wireshark='icq', chatproc='ICQ') = /[^o]icq/c and $icq;` * `fingerprint('fingerprint/phone/nokia/generic', 7.0) = 'user-agent: nokia' or 'profile: http://nds.nokia.com/uaprof/n';` Classification: TOP SECRET//COMINT//ORCON//REL TO USA, FVEY//20291123 --- Classification: TOP SECRET//COMINT//ORCON//REL TO USA, FVEY//20291123 ## Naming Conventions XKS Appid's are named using a pseudo directory convention. `/application_type/sub_type/name` Classification: TOP SECRET//COMINT//ORCON//REL TO USA, FVEY//20291123 --- Classification: TOP SECRET//COMINT//ORCON//REL TO USA, FVEY//20291123 ## Levels Levels are 1.0 – 9.9 with lower numbers having a higher priority. This allows multiple signatures to match a piece of traffic and only the most specific appid will be applied. An example might be: 9.9 Yahoo 9.8 Yahoo/chat 9.7 Yahoo/chat/incoming Since the Yahoo/chat/incoming has the lowest level, the traffic will be labeled as yahoo/chat/incoming Classification: TOP SECRET//COMINT//ORCON//REL TO USA, FVEY//20291123 --- Classification: TOP SECRET//COMINT//ORCON//REL TO USA, FVEY//20291123 ## Basic Search Patterns XKEYSCORE supports Boolean operations and regular expressions Raw text must be encapsulated between single quotes * 'search term' Terms can be combined with Boolean logic * 'search term' and 'another term' * 'search term' or 'another term' Classification: TOP SECRET//COMINT//ORCON//REL TO USA, FVEY//20291123 --- Classification: TOP SECRET//COMINT//ORCON//REL TO USA, FVEY//20291123 ## Binary and Regex Patterns Binary patterns can be represented by putting a \x in front of each binary value * `'\xff\xff\x00\x02'` Note: Unlike C, no double back slashing required `/regex/` Classification: TOP SECRET//COMINT//ORCON//REL TO USA, FVEY//20291123 --- Classification: TOP SECRET//COMINT//ORCON//REL TO USA, FVEY//20291123 ## CHAINWORDS You can assign a pattern to a variable (CHAINWORD) and reuse the variable in many patterns. * `$sip = 'via: sip' and 'cseq:' and 'SIP/2'c;` Now we can use this variable in future definitions: * `appid('voip/sip', 7.2 ) = $sip;` * `appid('voip/sip/invite', 6.9) = $sip and 'INVITE';` Classification: TOP SECRET//COMINT//ORCON//REL TO USA, FVEY//20291123 --- Classification: TOP SECRET//COMINT//ORCON//REL TO USA, FVEY//20291123 ## Built in functions | ip(expr) | Matches against an IP Address looks in to address and from address in the session headere
• ip('10.10.10.1'); | | :------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------- | | toport( expr) | Matches against the Destination/To port. Note this must be a numeric representation of a port.
• toport( 1920 ); | | fromport( expr) | Matches against the Source/From port. Note this must be a numeric representation of a port.
• fromport(80); | | port(expr) | Matches against the either port. Note this must be a numeric representation of a port.
•port(6667); | | next_protocol(expr) | Matches against the integer version of the next protocol.
• next_protocol(250); | | protocol ('text') | Will only work for IP next protocol names as defined in the IANA next protocol numbers document
• protocol('tcp'); | Classification: TOP SECRET//COMINT//ORCON//REL TO USA, FVEY//20291123 --- Classification: TOP SECRET//COMINT//ORCON//REL TO USA, FVEY//20291123 ## Built in functions | | | | :----------------- | :--------------------------------------------------------- | | email_address(sel) | permutes just like strong_selector (just like DECODEORDAIN | | mac_address(addr) | Tasks a mac address | | smac(addr) | | | dmac(addr) | | | ip(addr) | tasks this IP address (either to or from) | | from_ip(addr) | tasks this IP address only when it is the originator | | to_ip(addr) | tasks this IP address only when it is the destination | Classification: TOP SECRET//COMINT//ORCON//REL TO USA, FVEY//20291123 --- Classification: TOP SECRET//COMINT//ORCON//REL TO USA, FVEY//20291123 ## More built in functions | first(expr) | Matches against a pattern at the beginning of the session | | :------------ | :-------------------------------------------------------- | | lpos(expr) | Matches against a pattern at the beginning of each line (\n) | | pos( expr ) | expression occurs at offset X in the session
• pos('Hello') == 5,
• pos(/Good.*Grief/) <= 10 | | between(expr) | • between('Hello', 'World', 10, 100)
Separation between 'Hello' and 'World' is greater than or equal to 10 bytes and less than or equal to 100 bytes This is the same as using the following regular expression:
• /Hello.{10,100}World/ | | 'term'c | Does a case sensitive match of the term | | 'term'u | Treats the term as UTF-16 | Classification: TOP SECRET//COMINT//ORCON//REL TO USA, FVEY//20291123 --- Classification: TOP SECRET//COMINT//ORCON//REL TO USA, FVEY//20291123 ## Predefined Chainwords There are a number of chainwords predefined for convenience: * $tcp * $udp * $icmp * $sctp * $rpc * $arp * $ssl * $http_cmd * $http * $http_get * $http_put * $http_post * $http_delete * $http_trace * $http_head * $http_options * $http_partial * $vbulletin * $mime_type * $user_agent Classification: TOP SECRET//COMINT//ORCON//REL TO USA, FVEY//20291123 --- Classification: TOP SECRET//COMINT//ORCON//REL TO USA, FVEY//20291123 ## Example ``` appid('voip/sip/IMS', 6.0, wireshark='sip') = ('via: sip' or 'v: sip') and 'cseq:' and ( 'p-access-network-info:' or 'p-called-party-id:' or 'p-charging-vector:' or 'p-charging-vector-addresses:' or 'p-media-authorization:' or 'security-verify:' or 'security-server:' or 'security-client:' or 'service-route:' or 'record-route:' and 'pcscf' or 'record-route:' and 'scscf' or 'contact:' and 'pcscf' or 'contact:' and 'scscf' or 'proxy-authorization:' and 'pcscf' or 'proxy-authorization:' and 'scscf' or 'path:' and 'pcscf' or 'path:' and 'scscf' ); ``` Classification: TOP SECRET//COMINT//ORCON//REL TO USA, FVEY//20291123 --- Classification: TOP SECRET//COMINT//ORCON//REL TO USA, FVEY//20291123 ## Example ``` appid('voip/skinny/keep-alive', 3.0, wireshark='skinny') = toport(2000) and first('\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') ; appid('voip/skinny/keep-alive-ack', 3.0, wireshark='skinny') = fromport(2000) and first('\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') ; appid('voip/skinny(port2000)', 9.9, wireshark='skinny') = port(2000); ``` Classification: TOP SECRET//COMINT//ORCON//REL TO USA, FVEY//20291123 --- Classification: TOP SECRET//COMINT//ORCON//REL TO USA, FVEY//20291123 ## Example ``` appid('chat/yahoo', 6.0, chatproc='Yahoo') = (('YCHT'c and $yahoo_chat) or first('YCHT'c)) and not port(5050); appid('chat/icq', 8.5, wireshark='icq', chatproc='ICQ') = /[^o]icq/c and $icq; appid('chat/icq', 9.0, wireshark='icq', chatproc='ICQ') = first('icq') and not port(25); fingerprint('encryption/moujahedeen', 7.0) = 'begin+gimf+asrar+el+moujahedeen' or 'begin gimf asrar el moujahedeen'; ``` Classification: TOP SECRET//COMINT//ORCON//REL TO USA, FVEY//20291123 --- Classification: TOP SECRET//COMINT//ORCON//REL TO USA, FVEY//20291123 ## Example ``` appid('mail/smtp/to_server', 8.5, direction=$from_server, wireshark='smtp') = toport(25) and ( first('helo') or first('ehlo') or first('data') or (lpos('To: 'c) and lpos('From:'c)) or lpos('QUIT'c) or lpos('mail from:') or lpos('rcpt to:') ); ``` Classification: TOP SECRET//COMINT//ORCON//REL TO USA, FVEY//20291123 --- Classification: TOP SECRET//COMINT//ORCON//REL TO USA, FVEY//20291123 ## Example ``` $gmail = '