Login Register






There was a very particular style of DDOS attack just now, it was mitigated.
Thread Rating:
  • 0 Vote(s) - 0 Average


Tutorial Java and SSH filter_list
Author
Message
Java and SSH #1
In The Name OF Allah
Al-Salam Alekum

Hello guys, Long time because of my exams I hadn't time to come online. Today I'm going to explain using JSch library in Java to connect with SSH server, executing commands and downloading files. I hope ye all like it...

Start your IDE I'm using NetBeans. Add JSch library Download it from here

In this example we will connect to our server(VPS) through SSH and run a command (cd /var/www && ls).

PHP Code:
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ssh;

import java.io.InputStream;
import java.util.Properties;

import com.jcraft.jsch.ChannelExec;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;

public class 
SSHConnectionJava {
    public static 
void main(String[] args) {

    
//Host IP    
        
String host "1.1.1.1";
    
//Host User
        
String user "root";
    
//Host Password
        
String password "12345678";
                
        try {
            
Properties config = new Properties();
            
config.put("StrictHostKeyChecking""no");
            
JSch jsch = new JSch();
            
// Create a JSch session to connect to the server
            
Session session jsch.getSession(userhost22);
            
session.setPassword(password);
            
session.setConfig(config);
            
// Establish the connection
            
session.connect();
            
System.out.println("Connected...");
            
ChannelExec channel = (ChannelExecsession.openChannel("exec");
            
//Executing a command
            
channel.setCommand("cd /var/www/ && ls");
            
channel.setErrStream(System.err);
            
            
InputStream in channel.getInputStream();
            
channel.connect();
            
byte[] tmp = new byte[1024];
            while (
true) {
                while (
in.available() > 0) {
                    
int i in.read(tmp01024);
                    if (
0) {
                        break;
                    }
                    
System.out.print(new String(tmp0i));
                }
                if (
channel.isClosed()) {
                    
System.out.println("Exit Status: "
                        
channel.getExitStatus());
                        break;
                    }
                    
Thread.sleep(1000);
            }
                        
            
channel.disconnect();
            
session.disconnect();
            
System.out.println("DONE!!!");
    } catch (
Exception e) {
            
e.printStackTrace();
            }
    }
    


As you see in this image, it shows us html as a commands result.

[Image: p_1084wc7of1.png]

Now all depend on you for Backing up both your website files and SQL database using two commands instead of the one above:

Code:
zip -r /home/sinisterly.zip /var/www/ && mysqldump --all-databases > /home/all_databases.sql

This above will generate a zip files which include our files and the second command will generate a SQL file which include the whole databases data. Note: && separate the two commands.

Okay Let's download this files above:

PHP Code:
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ssh;
import com.jcraft.jsch.Channel;
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
import com.jcraft.jsch.SftpException;
/**
 * 
 * @author Kurdy
 *
 */
public class DownloadFileSFTP {
 
    public static 
void main(String[] argsthrows Exception {

        
JSch jsch = new JSch();
        
Session session null;
        try {
            
//Server User, IP and Port
            
session jsch.getSession("root""1.1.1.1"22);
            
session.setConfig("StrictHostKeyChecking""no");
            
//Server Password here...
            
session.setPassword("12345678");
            
session.connect();
            
            
Channel channel session.openChannel("sftp");
            
channel.connect();
            
//creating a FTP channel between you and the server
            
ChannelSftp sftpChannel = (ChannelSftpchannel;
            
//Downlaoding sinisterly.zip file to partiton D
            
sftpChannel.get("/home/sinisterly.zip""D:\\redsecurity.zip"); 
            
//Downloading all_databses.sql file to partition D
            
sftpChannel.get("/home/all_databases.sql""D:\\all_databases.sql");
            
System.out.println("Downloading Finished");
            
sftpChannel.exit();
            
session.disconnect();
        } catch (
JSchException e) {
            
e.printStackTrace();  
        } catch (
SftpException e) {
            
e.printStackTrace();
        }

   }



I'm done if you need anything feel free PMing me or posting here down...
Thank you for reading ......


Wa Salam Alekum
Die  But Don't Lie
“Oh Abu Dharr! Don’t look at the smallness of the sin but look at the one you disobeyed.” Prophet Muhammad (pbuh)
[Image: p_237m2jx1.png]
Click for Free VPN

[+] 1 user Likes Mr.Kurd's post
Reply

RE: Java and SSH #2
It's nice to have you back contributing quality tutorials.

Well done.
[Image: AD83g1A.png]

Reply

RE: Java and SSH #3
(12-21-2018, 05:10 AM)mothered Wrote: It's nice to have you back contributing quality tutorials.

Well done.

Thank you mothered, glad yo see you again.
Die  But Don't Lie
“Oh Abu Dharr! Don’t look at the smallness of the sin but look at the one you disobeyed.” Prophet Muhammad (pbuh)
[Image: p_237m2jx1.png]
Click for Free VPN

Reply

RE: Java and SSH #4
(12-21-2018, 04:01 PM)Mr.Kurd Wrote:
(12-21-2018, 05:10 AM)mothered Wrote: It's nice to have you back contributing quality tutorials.

Well done.

Thank you mothered, glad yo see you again.

Likewise.

Stay active.
[Image: AD83g1A.png]

[+] 1 user Likes mothered's post
Reply

RE: Java and SSH #5
(12-20-2018, 10:29 PM)Mr.Kurd Wrote:
In The Name OF Allah
Al-Salam Alekum

Hello guys, Long time because of my exams I hadn't time to come online. Today I'm going to explain using JSch library in Java to connect with SSH server, executing commands and downloading files. I hope ye all like it...

Start your IDE I'm using NetBeans. Add JSch library Download it from here

In this example we will connect to our server(VPS) through SSH and run a command (cd /var/www && ls).

PHP Code:
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ssh;

import java.io.InputStream;
import java.util.Properties;

import com.jcraft.jsch.ChannelExec;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;

public class 
SSHConnectionJava {
 
   public static void main(String[] args) {

 
//Host IP 
 
       String host "1.1.1.1";
 
//Host User
 
       String user "root";
 
//Host Password
 
       String password "12345678";
 
               
        try 
{
 
           Properties config = new Properties();
 
           config.put("StrictHostKeyChecking""no");
 
           JSch jsch = new JSch();
 
           // Create a JSch session to connect to the server
 
           Session session jsch.getSession(userhost22);
 
           session.setPassword(password);
 
           session.setConfig(config);
 
           // Establish the connection
 
           session.connect();
 
           System.out.println("Connected...");
 
           ChannelExec channel = (ChannelExecsession.openChannel("exec");
 
           //Executing a command
 
           channel.setCommand("cd /var/www/ && ls");
 
           channel.setErrStream(System.err);
 
           
            InputStream in 
channel.getInputStream();
 
           channel.connect();
 
           byte[] tmp = new byte[1024];
 
           while (true) {
 
            while (in.available() > 0) {
 
            int i in.read(tmp01024);
 
            if (0) {
 
            break;
 
            }
 
            System.out.print(new String(tmp0i));
 
            }
 
            if (channel.isClosed()) {
 
            System.out.println("Exit Status: "
 
                channel.getExitStatus());
 
                    break;
 
                   }
 
                   Thread.sleep(1000);
 
           }
 
                       
            channel
.disconnect();
 
           session.disconnect();
 
           System.out.println("DONE!!!");
 } catch (
Exception e) {
 
           e.printStackTrace();
 
           }
 }
 
   


As you see in this image, it shows us html as a commands result.

[Image: p_1084wc7of1.png]

Now all depend on you for Backing up both your website files and SQL database using two commands instead of the one above:

Code:
zip -r /home/sinisterly.zip /var/www/ && mysqldump --all-databases > /home/all_databases.sql

This above will generate a zip files which include our files and the second command will generate a SQL file which include the whole databases data. Note: && separate the two commands.

Okay Let's download this files above:

PHP Code:
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ssh;
import com.jcraft.jsch.Channel;
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
import com.jcraft.jsch.SftpException;
/**
 * 
 * @author Kurdy
 *
 */
public class DownloadFileSFTP {
 
 
   public static void main(String[] argsthrows Exception {

 
       JSch jsch = new JSch();
 
       Session session null;
 
       try {
 
           //Server User, IP and Port
 
           session jsch.getSession("root""1.1.1.1"22);
 
           session.setConfig("StrictHostKeyChecking""no");
 
           //Server Password here...
 
           session.setPassword("12345678");
 
           session.connect();
 
           
            Channel channel 
session.openChannel("sftp");
 
           channel.connect();
 
           //creating a FTP channel between you and the server
 
           ChannelSftp sftpChannel = (ChannelSftpchannel;
 
           //Downlaoding sinisterly.zip file to partiton D
 
           sftpChannel.get("/home/sinisterly.zip""D:\\redsecurity.zip"); 
 
           //Downloading all_databses.sql file to partition D
 
           sftpChannel.get("/home/all_databases.sql""D:\\all_databases.sql");
 
           System.out.println("Downloading Finished");
 
           sftpChannel.exit();
 
           session.disconnect();
 
       } catch (JSchException e) {
 
           e.printStackTrace();  
        
} catch (SftpException e) {
 
           e.printStackTrace();
 
       }

 
  }



I'm done if you need anything feel free PMing me or posting here down...
Thank you for reading ......


Wa Salam Alekum

very nice guide. I enjoy reading. Smile Cool
My IT skills that I know perfect is SQL, HTML ,css ,wordpress, PHP.
coding skills that I know is Java, JavaScript and C#

[+] 1 user Likes darkninja1980's post
Reply

RE: Java and SSH #6
(01-28-2019, 06:33 AM)darkninja1980 Wrote:
(12-20-2018, 10:29 PM)Mr.Kurd Wrote:
In The Name OF Allah
Al-Salam Alekum

Hello guys, Long time because of my exams I hadn't time to come online. Today I'm going to explain using JSch library in Java to connect with SSH server, executing commands and downloading files. I hope ye all like it...

Start your IDE I'm using NetBeans. Add JSch library Download it from here

In this example we will connect to our server(VPS) through SSH and run a command (cd /var/www && ls).

PHP Code:
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ssh;

import java.io.InputStream;
import java.util.Properties;

import com.jcraft.jsch.ChannelExec;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;

public class 
SSHConnectionJava {
 
   public static void main(String[] args) {

 
//Host IP 
 
       String host "1.1.1.1";
 
//Host User
 
       String user "root";
 
//Host Password
 
       String password "12345678";
 
               
        try 
{
 
           Properties config = new Properties();
 
           config.put("StrictHostKeyChecking""no");
 
           JSch jsch = new JSch();
 
           // Create a JSch session to connect to the server
 
           Session session jsch.getSession(userhost22);
 
           session.setPassword(password);
 
           session.setConfig(config);
 
           // Establish the connection
 
           session.connect();
 
           System.out.println("Connected...");
 
           ChannelExec channel = (ChannelExecsession.openChannel("exec");
 
           //Executing a command
 
           channel.setCommand("cd /var/www/ && ls");
 
           channel.setErrStream(System.err);
 
           
            InputStream in 
channel.getInputStream();
 
           channel.connect();
 
           byte[] tmp = new byte[1024];
 
           while (true) {
 
            while (in.available() > 0) {
 
            int i in.read(tmp01024);
 
            if (0) {
 
            break;
 
            }
 
            System.out.print(new String(tmp0i));
 
            }
 
            if (channel.isClosed()) {
 
            System.out.println("Exit Status: "
 
                channel.getExitStatus());
 
                    break;
 
                   }
 
                   Thread.sleep(1000);
 
           }
 
                       
            channel
.disconnect();
 
           session.disconnect();
 
           System.out.println("DONE!!!");
 } catch (
Exception e) {
 
           e.printStackTrace();
 
           }
 }
 
   


As you see in this image, it shows us html as a commands result.

[Image: p_1084wc7of1.png]

Now all depend on you for Backing up both your website files and SQL database using two commands instead of the one above:

Code:
zip -r /home/sinisterly.zip /var/www/ && mysqldump --all-databases > /home/all_databases.sql

This above will generate a zip files which include our files and the second command will generate a SQL file which include the whole databases data. Note: && separate the two commands.

Okay Let's download this files above:

PHP Code:
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ssh;
import com.jcraft.jsch.Channel;
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
import com.jcraft.jsch.SftpException;
/**
 * 
 * @author Kurdy
 *
 */
public class DownloadFileSFTP {
 
 
   public static void main(String[] argsthrows Exception {

 
       JSch jsch = new JSch();
 
       Session session null;
 
       try {
 
           //Server User, IP and Port
 
           session jsch.getSession("root""1.1.1.1"22);
 
           session.setConfig("StrictHostKeyChecking""no");
 
           //Server Password here...
 
           session.setPassword("12345678");
 
           session.connect();
 
           
            Channel channel 
session.openChannel("sftp");
 
           channel.connect();
 
           //creating a FTP channel between you and the server
 
           ChannelSftp sftpChannel = (ChannelSftpchannel;
 
           //Downlaoding sinisterly.zip file to partiton D
 
           sftpChannel.get("/home/sinisterly.zip""D:\\redsecurity.zip"); 
 
           //Downloading all_databses.sql file to partition D
 
           sftpChannel.get("/home/all_databases.sql""D:\\all_databases.sql");
 
           System.out.println("Downloading Finished");
 
           sftpChannel.exit();
 
           session.disconnect();
 
       } catch (JSchException e) {
 
           e.printStackTrace();  
        
} catch (SftpException e) {
 
           e.printStackTrace();
 
       }

 
  }



I'm done if you need anything feel free PMing me or posting here down...
Thank you for reading ......


Wa Salam Alekum

very nice guide. I enjoy reading. Smile Cool
Welcome man Wink
Die  But Don't Lie
“Oh Abu Dharr! Don’t look at the smallness of the sin but look at the one you disobeyed.” Prophet Muhammad (pbuh)
[Image: p_237m2jx1.png]
Click for Free VPN

Reply

RE: Java and SSH #7
(01-30-2019, 10:39 PM)Mr.Kurd Wrote:
(01-28-2019, 06:33 AM)darkninja1980 Wrote:
(12-20-2018, 10:29 PM)Mr.Kurd Wrote:
In The Name OF Allah
Al-Salam Alekum

Hello guys, Long time because of my exams I hadn't time to come online. Today I'm going to explain using JSch library in Java to connect with SSH server, executing commands and downloading files. I hope ye all like it...

Start your IDE I'm using NetBeans. Add JSch library Download it from here

In this example we will connect to our server(VPS) through SSH and run a command (cd /var/www && ls).

PHP Code:
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ssh;

import java.io.InputStream;
import java.util.Properties;

import com.jcraft.jsch.ChannelExec;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;

public class 
SSHConnectionJava {
 
   public static void main(String[] args) {

 
//Host IP 
 
       String host "1.1.1.1";
 
//Host User
 
       String user "root";
 
//Host Password
 
       String password "12345678";
 
               
        try 
{
 
           Properties config = new Properties();
 
           config.put("StrictHostKeyChecking""no");
 
           JSch jsch = new JSch();
 
           // Create a JSch session to connect to the server
 
           Session session jsch.getSession(userhost22);
 
           session.setPassword(password);
 
           session.setConfig(config);
 
           // Establish the connection
 
           session.connect();
 
           System.out.println("Connected...");
 
           ChannelExec channel = (ChannelExecsession.openChannel("exec");
 
           //Executing a command
 
           channel.setCommand("cd /var/www/ && ls");
 
           channel.setErrStream(System.err);
 
           
            InputStream in 
channel.getInputStream();
 
           channel.connect();
 
           byte[] tmp = new byte[1024];
 
           while (true) {
 
            while (in.available() > 0) {
 
            int i in.read(tmp01024);
 
            if (0) {
 
            break;
 
            }
 
            System.out.print(new String(tmp0i));
 
            }
 
            if (channel.isClosed()) {
 
            System.out.println("Exit Status: "
 
                channel.getExitStatus());
 
                    break;
 
                   }
 
                   Thread.sleep(1000);
 
           }
 
                       
            channel
.disconnect();
 
           session.disconnect();
 
           System.out.println("DONE!!!");
 } catch (
Exception e) {
 
           e.printStackTrace();
 
           }
 }
 
   


As you see in this image, it shows us html as a commands result.

[Image: p_1084wc7of1.png]

Now all depend on you for Backing up both your website files and SQL database using two commands instead of the one above:

Code:
zip -r /home/sinisterly.zip /var/www/ && mysqldump --all-databases > /home/all_databases.sql

This above will generate a zip files which include our files and the second command will generate a SQL file which include the whole databases data. Note: && separate the two commands.

Okay Let's download this files above:

PHP Code:
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ssh;
import com.jcraft.jsch.Channel;
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
import com.jcraft.jsch.SftpException;
/**
 * 
 * @author Kurdy
 *
 */
public class DownloadFileSFTP {
 
 
   public static void main(String[] argsthrows Exception {

 
       JSch jsch = new JSch();
 
       Session session null;
 
       try {
 
           //Server User, IP and Port
 
           session jsch.getSession("root""1.1.1.1"22);
 
           session.setConfig("StrictHostKeyChecking""no");
 
           //Server Password here...
 
           session.setPassword("12345678");
 
           session.connect();
 
           
            Channel channel 
session.openChannel("sftp");
 
           channel.connect();
 
           //creating a FTP channel between you and the server
 
           ChannelSftp sftpChannel = (ChannelSftpchannel;
 
           //Downlaoding sinisterly.zip file to partiton D
 
           sftpChannel.get("/home/sinisterly.zip""D:\\redsecurity.zip"); 
 
           //Downloading all_databses.sql file to partition D
 
           sftpChannel.get("/home/all_databases.sql""D:\\all_databases.sql");
 
           System.out.println("Downloading Finished");
 
           sftpChannel.exit();
 
           session.disconnect();
 
       } catch (JSchException e) {
 
           e.printStackTrace();  
        
} catch (SftpException e) {
 
           e.printStackTrace();
 
       }

 
  }



I'm done if you need anything feel free PMing me or posting here down...
Thank you for reading ......


Wa Salam Alekum

very nice guide. I enjoy reading. Smile  Cool
Welcome man Wink

No problem.
My IT skills that I know perfect is SQL, HTML ,css ,wordpress, PHP.
coding skills that I know is Java, JavaScript and C#

Reply

RE: Java and SSH #8
@"Mr.Kurd", you did mention that you won't contribute anymore, but I hope to see more of your HQ tutorials.
[Image: AD83g1A.png]

Reply

RE: Java and SSH #9
(01-31-2019, 02:51 AM)mothered Wrote: @"Mr.Kurd", you did mention that you won't contribute anymore, but I hope to see more of your HQ tutorials.

I like reading his guides as well. Smile
My IT skills that I know perfect is SQL, HTML ,css ,wordpress, PHP.
coding skills that I know is Java, JavaScript and C#

Reply

RE: Java and SSH #10
(01-31-2019, 02:51 AM)mothered Wrote: @"Mr.Kurd", you did mention that you won't contribute anymore, but I hope to see more of your HQ tutorials.
Actually, @"mothered" Java section here on SL is very inactive and members not showing interest. You see spending much time to write an HQ tutorial but members are not showing interest so it's pretty much tiring.
Die  But Don't Lie
“Oh Abu Dharr! Don’t look at the smallness of the sin but look at the one you disobeyed.” Prophet Muhammad (pbuh)
[Image: p_237m2jx1.png]
Click for Free VPN

Reply







Users browsing this thread:






This forum uses Lukasz Tkacz MyBB addons.