Protecting JSON applications using signatures
-
application/x-javascript
-
text/javascript
-
text/x-javascript
-
text/x-json
Using the NetScaler Web App Firewall signatures to protect JSON applications
> sh appfw jsonContentType
1) JSONContenttypevalue: "^application/json$" IsRegex: REGEX
Done
-
application/x-www-form-urlencoded
-
multipart/form-data
-
text/x-gwt-rpc
To add or remove JSON content-type by using the command line interface
add appfw jsonContentType \^application/json$ IsRegEx REGEX
rm appfw JSONContentType "\^application/json$"
To managing JSON content types by using the GUI
Configuring signature protection to detect attacks in JSON payload
Example of a signature to detect cross-site scripting in JSON payload
<SignatureRule actions="log,stats" category="JSON" enabled="ON" id="1000001" severity="" source="" type="" version="1">
<PatternList>
<RequestPatterns>
<Pattern>
<Location area="HTTP_POST_BODY"/>
<Match type="Expression">TEXT.XPATH_JSON(xp%/glossary/title%).CONTAINS("example glossary")</Match>
</Pattern>
<Pattern>
<Location area="HTTP_METHOD"/>
<Match type="LITERAL">POST</Match>
</Pattern>
<Pattern>
<Location area="HTTP_POST_BODY"/>
<Match type="CrossSiteScripting"/>
</Pattern>
</RequestPatterns>
</PatternList>
<LogString>Cross-site scripting violation detected in json payload</LogString>
<Comment/>
</SignatureRule>
Example of the payload
{"glossary": {"title": "example glossary","GlossDiv": {"title": "S","GlossList": {"GlossEntry": {"ID": "SGML","SortAs": "SGML","GlossTerm": "Standard Generalized Markup Language","Acronym": "SGML","Abbrev": "ISO 8879:1986","GlossDef": {"para": "A meta-markup language, used to create markup languages **<Gotcha!!>** such as DocBook.","GlossSeeAlso": ["GML", "XML"]},"GlossSee": "markup"}}}}}
Example of the log message
Aug 21 12:21:42 <local0.info> 10.217.31.239 08/21/2015:23:21:42 GMT ns 0-PPE-1 : APPFW APPFW_SIGNATURE_MATCH 1471 0 : 10.217.253.62 990-PPE0 NtJnVMNnvPeQJnaUzXYW/GTvAQsA010 prof1 http://10.217.31.212/FFC/login_post.php Signature violation rule ID 1000001: cross-site scripting violation detected in json payload <not blocked>
Highlights
-
To protect JSON payload, use Web App Firewall signatures to detect cross-site scripting, SQL and other violations.
-
Verify that the JSON content type is configured on the appliance as the allowed content type.
-
Make sure that the content type in the payload matches the configured JSON content type.
-
Make sure that all the patterns configured in the signature rule match for the signature violation to be triggered.
-
When you add a signature rule, it MUST have at least one Rule pattern to match the Expression in the JSON payload. All the PI expressions in signature rules must start with the prefix TEXT. and must be Boolean.
Protect application or JSON content-type with SQL and cross-site scripting encoded payload using policies and signatures
Inspect application or JSON content type for SQL injection using policies
add appfw policy sqli_1 HTTP.REQ.BODY(10000).SET_TEXT_MODE(IGNORECASE).SET_TEXT_MODE(URLENCODED).DECODE_USING_TEXT_MODE.REGEX_MATCH(re#(((\\A)|(?<=[\^a-zA-Z0-9_])))(select|insert|delete|update|drop|create|alter|grant|revoke|commit|rollback|shutdown|union|intersect|minus|case|decode|where|group|begin|join|exists|distinct|add|modify|constraint|null|like|exec|execute|char|or|and|sp_sdidebug)((Z)|(?=[\^a-zA-Z0-9_]))#) APPFW_BLOCK
add appfw policy sqli_2 HTTP.REQ.BODY(10000).SET_TEXT_MODE(IGNORECASE).SET_TEXT_MODE(URLENCODED).DECODE_USING_TEXT_MODE.REGEX_MATCH(re#((\\A)|(?<=[\^a-zA-Z0-9_]))(xp_availablemedia|xp_cmdshell|xp_deletemail|xp_dirtree|xp_dropwebtask|xp_dsninfo|xp_enumdsn|xp_enumerrorlogs|xp_enumgroups|xp_enumqueuedtasks|xp_eventlog|xp_findnextmsg|xp_fixeddrives|xp_getfiledetails|xp_getnetname|xp_grantlogin|xp_logevent|xp_loginconfig|xp_logininfo|xp_makewebtask|xp_msver|xp_regread|xp_perfend|xp_perfmonitor|xp_perfsample|xp_perfstart|xp_readerrorlog|xp_readmail|xp_revokelogin|xp_runwebtask|xp_schedulersignal|xp_sendmail|xp_servicecontrol|xp_snmp_getstate|xp_snmp_raisetrap|xp_sprintf|xp_sqlinventory|xp_sqlregister|xp_sqltrace|xp_sscanf|xp_startmail|xp_stopmail|xp_subdirs|xp_unc_to_drive)((Z)|(?=[\^a-zA-Z0-9_]))#) APPFW_BLOCK
add appfw policy sqli_3 HTTP.REQ.BODY(10000).SET_TEXT_MODE(IGNORECASE).SET_TEXT_MODE(URLENCODED).DECODE_USING_TEXT_MODE.REGEX_MATCH(re#((\\A)|(?<=[\^a-zA-Z0-9_]))(sysobjects|syscolumns|MSysACEs|MSysObjects|MSysQueries|MSysRelationships)((Z)|(?=[\^a-zA-Z0-9_]))#) APPFW_BLOCK
add appfw policy sqli_4 HTTP.REQ.BODY(10000).SET_TEXT_MODE(IGNORECASE).SET_TEXT_MODE(URLENCODED).DECODE_USING_TEXT_MODE.REGEX_MATCH(re#((\\A)|(?<=[\^a-zA-Z0-9_]))(SYS\.USER_OBJECTS|SYS\.TAB|SYS\.USER_TABLES|SYS\.USER_VIEWS|SYS\.ALL_TABLES|SYS\.USER_TAB_COLUMNS|SYS\.USER_CONSTRAINTS|SYS\.USER_TRIGGERS|SYS\.USER_CATALOG|SYS\.ALL_CATALOG|SYS\.ALL_CONSTRAINTS|SYS\.ALL_OBJECTS|SYS\.ALL_TAB_COLUMNS|SYS\.ALL_TAB_PRIVS|SYS\.ALL_TRIGGERS|SYS\.ALL_USERS|SYS\.ALL_VIEWS|SYS\.USER_ROLE_PRIVS|SYS\.USER_SYS_PRIVS|SYS\.USER_TAB_PRIVS)((Z)|(?=[\^a-zA-Z0-9_]))#) APPFW_BLOCK
Inspect application or JSON content type using signatures
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright 2013-2018 Citrix Systems, Inc. All rights reserved. -->
<SignaturesFile schema_version="6" version="0" minor_schema_version="0">
<Signatures>
<SignatureRule id="4000000" enabled="ON" actions="log,block" category="sql" source="" severity="" type="" version="1" sourceid="" harmscore="">
<PatternList>
<RequestPatterns>
<Pattern>
<Location area="HTTP_POST_BODY"/>
<Match type="Expression">TEXT.SET_TEXT_MODE(IGNORECASE).SET_TEXT_MODE(URLENCODED).DECODE_USING_TEXT_MODE.REGEX_MATCH(re#(((\\A)|(?<=[^a-zA-Z0-9_])))(select|insert|delete|update|drop|create|alter|grant|revoke|commit|rollback|shutdown|union|intersect|minus|case|decode|where|group|begin|join|exists|distinct|add|modify|constraint|null|like|exec|execute|char|or|and|sp_sdidebug)((
Z)|(?=[^a-zA-Z0-9_]))#)</Match>
</Pattern>
<Pattern type="fastmatch">
<Location area="HTTP_METHOD"/>
<Match type="LITERAL">T</Match>
</Pattern>
</RequestPatterns>
</PatternList>
<LogString>sql Injection</LogString>
<Comment/>
</SignatureRule>
<SignatureRule id="4000001" enabled="ON" actions="log,block" category="sql" source="" severity="" type="" version="1" sourceid="" harmscore="">
<PatternList>
<RequestPatterns>
<Pattern>
<Location area="HTTP_POST_BODY"/>
<Match type="Expression">TEXT.SET_TEXT_MODE(IGNORECASE).SET_TEXT_MODE(URLENCODED).DECODE_USING_TEXT_MODE.REGEX_MATCH(re#((\\A)|(?<=[^a-zA-Z0-9_]))(xp_availablemedia|xp_cmdshell|xp_deletemail|xp_dirtree|xp_dropwebtask|xp_dsninfo|xp_enumdsn|xp_enumerrorlogs|xp_enumgroups|xp_enumqueuedtasks|xp_eventlog|xp_findnextmsg|xp_fixeddrives|xp_getfiledetails|xp_getnetname|xp_grantlogin|xp_logevent|xp_loginconfig|xp_logininfo|xp_makewebtask|xp_msver|xp_regread|xp_perfend|xp_perfmonitor|xp_perfsample|xp_perfstart|xp_readerrorlog|xp_readmail|xp_revokelogin|xp_runwebtask|xp_schedulersignal|xp_sendmail|xp_servicecontrol|xp_snmp_getstate|xp_snmp_raisetrap|xp_sprintf|xp_sqlinventory|xp_sqlregister|xp_sqltrace|xp_sscanf|xp_startmail|xp_stopmail|xp_subdirs|xp_unc_to_drive)((
Z)|(?=[^a-zA-Z0-9_]))#)</Match>
</Pattern>
<Pattern type="fastmatch">
<Location area="HTTP_METHOD"/>
<Match type="LITERAL">T</Match>
</Pattern>
</RequestPatterns>
</PatternList>
<LogString>sql Injection</LogString>
<Comment/>
</SignatureRule>
<SignatureRule id="4000002" enabled="ON" actions="log,block" category="sql" source="" severity="" type="" version="1" sourceid="" harmscore="">
<PatternList>
<RequestPatterns>
<Pattern>
<Location area="HTTP_POST_BODY"/>
<Match type="Expression">TEXT.SET_TEXT_MODE(IGNORECASE).SET_TEXT_MODE(URLENCODED).DECODE_USING_TEXT_MODE.REGEX_MATCH(re#((\\A)|(?<=[^a-zA-Z0-9_]))(sysobjects|syscolumns|MSysACEs|MSysObjects|MSysQueries|MSysRelationships)((
Z)|(?=[^a-zA-Z0-9_]))#)</Match>
</Pattern>
<Pattern type="fastmatch">
<Location area="HTTP_METHOD"/>
<Match type="LITERAL">T</Match>
</Pattern>
</RequestPatterns>
</PatternList>
<LogString>sql Injection</LogString>
<Comment/>
</SignatureRule>
<SignatureRule id="4000003" enabled="ON" actions="log,block" category="sql" source="" severity="" type="" version="1" sourceid="" harmscore="">
<PatternList>
<RequestPatterns>
<Pattern>
<Location area="HTTP_POST_BODY"/>
<Match type="Expression">TEXT.SET_TEXT_MODE(IGNORECASE).SET_TEXT_MODE(URLENCODED).DECODE_USING_TEXT_MODE.REGEX_MATCH(re#((\\A)|(?<=[^a-zA-Z0-9_]))(SYS\.USER_OBJECTS|SYS\.TAB|SYS\.USER_TABLES|SYS\.USER_VIEWS|SYS\.ALL_TABLES|SYS\.USER_TAB_COLUMNS|SYS\.USER_CONSTRAINTS|SYS\.USER_TRIGGERS|SYS\.USER_CATALOG|SYS\.ALL_CATALOG|SYS\.ALL_CONSTRAINTS|SYS\.ALL_OBJECTS|SYS\.ALL_TAB_COLUMNS|SYS\.ALL_TAB_PRIVS|SYS\.ALL_TRIGGERS|SYS\.ALL_USERS|SYS\.ALL_VIEWS|SYS\.USER_ROLE_PRIVS|SYS\.USER_SYS_PRIVS|SYS\.USER_TAB_PRIVS)((
Z)|(?=[^a-zA-Z0-9_]))#)</Match>
</Pattern>
<Pattern type="fastmatch">
<Location area="HTTP_METHOD"/>
<Match type="LITERAL">T</Match>
</Pattern>
</RequestPatterns>
</PatternList>
<LogString>sql Injection</LogString>
<Comment/>
</SignatureRule>
</Signatures>
</SignaturesFile>