RSS

Category Archives: Defense

How to use Java in the Enterprise while Limiting Exposure with IE Trusted Sites

Summary

Java has become a difficult software to wrangle in the past 18 months due to the number of exploits released. Unfortunately, most enterprises have at least one critical application that relies on this technology. To limit its attack surface, I suggest using a whitelist approach. For the most compatibility in corporate environments, I’m using IE as the browser that has Java enabled and manage these settings in GPO. To make sure users do not have other browsers with Java enabled on the same system, we will disable it for both Google Chrome and Mozilla Firefox.

Currently, it does not appear to be a good way to whitelist “Java Web Start” applications. Due to this issue, my recommendation is to currently disable this feature at this time. You may need to create an exempt group if this is a required feature for certain individuals or group in your organizations.

Deployment Options

These settings will need to be applied every time Java or when your web browsers are updated at minimum. It’s best to have these settings applied via GPO or at every log in. The GPO.bat file can be replaced by adding the registry setting into a GPO preference.  The files can be found here.

Note: Even though these setting have been tested on both XP and Win7 please test them in your environment before deploying. All settings are based on 32-bit Java. If you are running the 64-bit version, these setting can easily be modified to meet that need.

GPO

To deploy these settings using GPO you will need to:

  1. Add to the Trusted Sites
  2. Implement the GPO section for each of the implementation sections below
  3. Deploy the gpo.bat and disable_java_firefox.vbs, via GPO,  The gpo.bat only makes registry changes not directly manageable from GPO.
  4. Disable Java in Chrome.

Windows Batch

If you are planning to use the batch only option they should be ran with Admin privileges.

  1. Add to the Trusted Sites via GPO
  2. Disable Java in Chrome
  3. Copy the java.bat and disable_Java_firefox.vbs to a network share and make sure its ran with Admin privileges on all systems

Implementation

Adding Trusted Sites

To manage this setting via GPO

User Config > Admin Templates >Windows Components > Internet Explorer >Internet Control Panel >Security Page> Site to Zone Assignment list

To add a zone the Value name is the site you want to whitelist and the value is what zone you want to add it to. To add to trusted zone always set the value to 2.

*.wordpress.com 2

To add a specific site and not an entire domain

http://www.mywebsite.com 2

Disable Java in Firefox

The Disable_Java_firefox VB script by @integrisec modifies the pluginreg.dat file in the Mozilla profile directory and sets the Java plugin to disabled. I had to modify the version from his the website to better adjust the disable logic. This is called by my batch script and needs to be in the same directory as the batch file.

Disable Java in Chrome

The easiest way to disable Java in Google chrome is by changing the shortcut to chrome.exe –disable-java. Setup a batch file to copy a new one from a network share to the user’s desktop/start menu.

Via GPO

  • You can change the shortcut using GPO
  • You can fully manage Chrome from GPO if you import the template. This is cumbersome if you are only using this to manage Java, but it you are already managing it this way below are the settings.

Computer Config > Admin Templates > Classic Admin Template >Google > Google Chrome > Specify a list of disable plugins > Enable

  • Add *Java*

Internet Explorer

We are going to lock-down all the ways Java can be called and make sure that it will use the IE trusted zone list. The post at greyhathacker.net does an awesome job breaking down many of the issues and prevention methods and several of the suggestions are implemented below.

Java Applet settings

Disable the Java applet from running in any zone except in Trusted Zone.

Via GPO

Admin Template > Windows Components > Internet Explorer > Internet Control Panel > Security Page

> Intranet Zone >

  • Java Permissions-> Enable Plugin >Disable Java

>Internet Zone >

  • Java Permissions-> Enable Plugin >Disable Java

>Trusted Zone

  • Java Permissions-> Enable Plugin >Enable Java

>Restricted Zone

  • Java Permissions-> Enable Plugin >Disable Java

Via Registry

For all zones the registry setting 1C00 DWORD value should be set to 0 except for the Trusted and Intranet zone which should be 0×00010000.

reg add “HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\1″ /v 1c00 /t REG_DWORD /d 0×00 /f

reg add “HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\2″ /v 1c00 /t REG_DWORD /d 0×00010000 /f

reg add “HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3″ /v 1c00 /t REG_DWORD /d 0×00 /f

reg add “HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\4″ /v 1c00 /t REG_DWORD /d 0×00 /f

Disable scripting of Java applets in other zones

Via GPO

Admin Template > Windows Components > Internet Explorer > Internet Control Panel > Security Page > Internet Zone >

  • Scripting for Java applets > Enable Plugin > Disable

> Intranet Zone >

  • Scripting for Java applets > Enable Plugin > Disable

>Restricted Zone

  • Scripting for Java applets > Enable Plugin > Disable

Via Registry

reg add “HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\1″ /v 1402 /t REG_DWORD /d 0×03 /f

reg add “HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3″ /v 1402 /t REG_DWORD /d 0×03 /f

reg add “HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\4″ /v 1402 /t REG_DWORD /d 0×03 /f

Java Object Tags

Java object tags are handled differently in IE. You will need to modify the ActiveX control to only allow trusted sites to call these objects.

Limit Java Objects tags

According to Microsoft, If you remove the ‘*’ then it will not load the object tags from the Internet zone and only the trusted zone and Intranet zone.

Registry Only

reg add “HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Ext\Stats\{8AD9C840-044E-11D1-B3E9-00805F499D93}\iexplore\AllowedDomains” /f

reg delete “HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Ext\Stats\{8AD9C840-044E-11D1-B3E9-00805F499D93}\iexplore\AllowedDomains\*” /f

Prevent users from adding sites to the trusted Java plug-in list.

This prevents the Security Band from popping up when visiting non-trusted sites.

Registry Only

reg add “HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_SECURITYBAND“ /v iexplore.exe /t REG_DWORD /d 0×00 /f

Do not allow users to add/remove sites from the Trusted sites

Via GPO

Computer Configuration\Administrative Templates\Windows Components\Internet Explorer > Security Zones: Do not allow users to add/delete sites

Via Registry

Reg add “HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\CurrentVersion\Internet Settings” /v Security_options_edit /t REG_DWORD /d 0×01 /f

Break Functionality of Java Web Start

Java Web Start downloads a java file and executes java outside the browser. Currently I have not found a way to force this to use IE zones before it’s executed. Therefore we cannot limit its access so we must break this function.

Registry Only

reg add “HKEY_LOCAL_MACHINE\SOFTWARE\Classes\JNLPFile\Shell\Open\Command” /t REG_SZ /d “iexplore.exe” /f

reg add “HKEY_LOCAL_MACHINE\SOFTWARE\Classes\JNLPFile” /t REG_BINARY /v EditFlags /d 00000000 /f

reg add “HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer\ActiveX Compatibility\{5852F5ED-8BF4-11D4-A245-0080C6F74284}” /v “Compatibility Flags” /t REG_DWORD /d 00000400 /f

reg add “HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\Internet Explorer\ActiveX Compatibility\{5852F5ED-8BF4-11D4-A245-0080C6F74284}” /v “Compatibility Flags” /t REG_DWORD /d 00000400 /f

Disable Java Development Toolkit Active X control

Registry Only

Reg add “HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer\ActiveX Compatibility\{CAFEEFAC-DEC7-0000-0001-ABCDEFFEDCBA}” /t REG_DWORD /v “Compatibility Flags” /d 00000400 /f

Sites to test java settings.

Below is a list of sites to test the Java settings are working correctly. While most of these sites simply demonstrate specific ways to call java, sites have not been analyzed for malware and should be considered dangerous. Once configured none of them should be able to load Java in the browser unless it’s listed as a trusted site. Only visit them on a virtual machine and have it reverted back to previous settings once it’s tested.

https://eyeasme.com/Shayne/XHTML/appletObject.html

http://www.w3.org/2000/07/8378/object/java/clock

http://www.brainjar.com/java/parameters/demo.html

http://www.java.com/en/download/testjava.jsp

http://www.codebrain.com/java/navajo/index_embed.html

http://www.twainconnect.com/jnlp/Default.aspx

http://source.db4o.com/db4o/trunk/objectmanager-swing/webstart/sample.html

 
Leave a comment

Posted by on March 26, 2013 in Defense

 

Tags: , , , , , ,

MySQL Stored Procedure, Prepared Statements and SQL Injection

I’ve been working on a MySQL project lately. This application does not take input directly from the user, but it still has to query the database to setup variables to then input data.

I wanted to be sure that I was using the best technique for preventing SQL injection. Originally I was planning to use a stored procedure and escape the input parameter, but I found out about prepared statements. It works by setting up the SQL statement and setting a place holder with a ‘?’ for input. What this does is tells MySQL to read this as data and prevents attackers from changing the query results.

'Select * from table where name is ?'

You can have your VB.net, PHP or other languages build the prepared statement for you, but I wanted to build the logic on the server side. This give the client access to execute the stores procedure and not allow direct permissions to the tables.

The basic syntax for a prepared statement is you prepare the statement with a name, give the SQL query to preform, execute the statement and then deallocate the statement.

prepare id from
 'select Id from table where name= ?' ;
 set @myname :='mycomputer';
 execute id @myname;
 DEALLOCATE PREPARE id;

The sql statement above does the following:

  1. Sets the name of the statement to “id”
  2. Sets the SQL statement and has a place holder for the name in the query
  3. Sets the variable @myname to “mycomputer”
  4. Executes the statement “id” using the variable @myname as the query value ‘?’
  5. Removes the prepared statement

Using the information above. The statement that is run is

'select Id from table where name= mycomputer' ;

Now I want to take the prepared statement and make it a stored procedure.

 DROP PROCEDURE IF EXISTS `table`.`get_id`;
 DELIMITER $$
 CREATE PROCEDURE `IR`.`get_id`(IN input VARCHAR(20), OUT id VARCHAR(5))
 READS SQL DATA
 BEGIN
 SET @input=input;
 prepare id from
 'select Id from table where name= ?' ;
 execute id USING @input;
 DEALLOCATE PREPARE id;
 END$$
  1. If the procedure already exists, delete it
  2. Setup the delimiter for starting and stoping the procedure text
  3. Creates the procedure name get_id in the table. It allows input of up to 20 characters and allows output to be up to 5 characters. By limiting the input and output, if injection is possible, it makes it more difficult.
  4. Reads data tells MySQL you are only reading data and not updating information
  5. Begin tells MySQL this is the start of the main procedure
  6. Creates a variable input for data that is supplied to the stored procedure
  7. The rest is the same as previously discussed
Next, we need to give permission to the user to run the procedure.
mysql>;;Grant execute on get_id to 'me'@'localhost'

To run the stored procedure from the MYSQL console, you do the following:

mysql>;;call get_id('mycomputer', @out);
+-------+
 | @out |
 +------+
 | 1    |
 +------+

Once you have the output you want from the procedure, you can now call it from any program you want. Some of the more common languages to call stored procedures are: PHP, ASP and VB.net

 
Leave a comment

Posted by on October 29, 2012 in Defense

 

Tags: , , ,

Determine Rogue DNS for IP Space

Determining what domains are registered to a network is important to both attackers and defenders. Attackers have been performing DNS recon for years, but defenders generally do not use this technique. Why would we need to? We can just get a dump of the DNS database and search it. Well this only works for domains that you control, but users can point to your IP space with a different domain name and you would never know about it. This could be a legitimate subsidiary standing up a site, or it could be a rogue server “borrowing bandwidth”. Either way it’s better to know these things before attackers do.

I wrote a bash script (Tested on Ubuntu and OSX) to use the robtex’s website to determine what DNS names have been assigned to a specific network. Their website looks up DNS names based on class C networks. For class A and B networks, it will break them down into class c networks and query the site. The results are displayed to standard out in csv format.

Lets try this out on a Google subnet.

#nslookup google.com
Name: google.com Address: 74.125.67.105
#./dns_recon.sh 74.125.67 >74.125.67.csv

The file looks like this.

#head 74.125.67.csv
 gw-in-f16.1e100.net,a,74.125.67.16
 gw-in-f17.1e100.net,a,74.125.67.17
 gw-in-f18.1e100.net,a,74.125.67.18
 mail.miamichildrensmuseum.org,a,74.125.67.18
 gw-in-f19.1e100.net,a,74.125.67.19
 gmr-test.google.com,a,74.125.67.23
 gw-in-f23.1e100.net,a,74.125.67.23
 a.mx.systembrasil.com.br,a,74.125.67.27
 alt2.aspmx.l.ipmgr.net,a,74.125.67.27
 alt22.aspmx.l.google.com,a,74.125.67.27

Lets quickly see what other domains besides google.com are listed by filtering out google.com. You can also import this into a spreadsheet and filter your results with it.

#grep -v google.com 74.126.76.txt
...(trunckated)
velure.info,a,74.125.67.100
youtube.ca,a,74.125.67.100
youtube.co.il,a,74.125.67.100
youtube.co.in,a,74.125.67.100
...(truncated)

This technique has worked out great for me. I have the user agent set as a Yahoo crawler, but you can change the variable to anything you like.

 
Leave a comment

Posted by on July 17, 2011 in Defense, Pentest

 

Tags: , ,

 
Follow

Get every new post delivered to your Inbox.