Login as root in Linux from Netbeans

Hi to all,I am to login as root by pressing a button in a JFrame ;Does anyone have any idea?Thanks
[126 byte] By [Vladislava] at [2007-11-27 6:21:37]
# 1
> Hi to all,> I am to login as root by pressing a button in a> JFrame ;> Does anyone have any idea?Yes. Don't do this.
cotton.ma at 2007-7-12 17:38:13 > top of Java-index,Java Essentials,Java Programming...
# 2
How come ?Why ?
Vladislava at 2007-7-12 17:38:13 > top of Java-index,Java Essentials,Java Programming...
# 3
> How come ?Why ?Because it's dangerous?
cotton.ma at 2007-7-12 17:38:13 > top of Java-index,Java Essentials,Java Programming...
# 4
what can it happen ?
Vladislava at 2007-7-12 17:38:13 > top of Java-index,Java Essentials,Java Programming...
# 5
> what can it happen ?Many bad things. The fact you are having to ask suggests this is a really bad idea.How about instead of this discussion we discuss what problem you are actually trying to solve instead and see if we can come up with a more suitable solution.
cotton.ma at 2007-7-12 17:38:13 > top of Java-index,Java Essentials,Java Programming...
# 6
You are right , so any ideas?
Vladislava at 2007-7-12 17:38:13 > top of Java-index,Java Essentials,Java Programming...
# 7
> You are right , so any ideas?What is the exact nature of the problem you are trying to solve?
cotton.ma at 2007-7-12 17:38:13 > top of Java-index,Java Essentials,Java Programming...
# 8
> > You are right , so any ideas?> > What is the exact nature of the problem you are> trying to solve?Hacking r00t
filestreama at 2007-7-12 17:38:13 > top of Java-index,Java Essentials,Java Programming...
# 9
I want to execute an application from java ,but this application will start only if you are root , so first I want to log as root and second to start that application
Vladislava at 2007-7-12 17:38:13 > top of Java-index,Java Essentials,Java Programming...
# 10

> I want to execute an application from java ,but this

> application will start only if you are root , so

> first I want to log as root and second to start that

> application

What is this application?

There is probably some very good reason for you to have to be root to execute it...

cotton.ma at 2007-7-12 17:38:13 > top of Java-index,Java Essentials,Java Programming...
# 11
snort
Vladislava at 2007-7-12 17:38:13 > top of Java-index,Java Essentials,Java Programming...
# 12
> snortCocaine can give you cancer when snorted so I would advise against 'snort'.
sabre150a at 2007-7-12 17:38:13 > top of Java-index,Java Essentials,Java Programming...
# 13
> > snort> > Cocaine can give you cancer when snorted so I would> advise against 'snort'.snort can be run from Knoppix.
filestreama at 2007-7-12 17:38:13 > top of Java-index,Java Essentials,Java Programming...
# 14
I want to execute start/restart/stop Snort from a Java application ,so that I want to execute first as root
Vladislava at 2007-7-12 17:38:13 > top of Java-index,Java Essentials,Java Programming...
# 15
any ideas?
Vladislava at 2007-7-21 21:51:49 > top of Java-index,Java Essentials,Java Programming...
# 16
What's the big deal? Sign on as root, run your application. Netbeans is irrelevant to this process.
DrClapa at 2007-7-21 21:51:49 > top of Java-index,Java Essentials,Java Programming...
# 17

> I want to execute start/restart/stop Snort from a

> Java application ,so that I want to execute first as

> root

You could do some magic with Runtime.exec, after detecting platform and environment (I don't know if possible for Win/Mac, but I wouldn't think you're running snort under those platforms anyway)...

Process p = null;

String[] cmd;

if ( isKDE() ) { // detect process kdeinit

cmd = new String[] {"gksu", "/etc/init.d/snort", "start"};

} else if ( isGnome() ) { // detect gnome-settings-daemon/something similar

cmd = new String[] {"kdesu", "/etc/init.d/snort", "start"};

} else {

cmd = null;

}

if (null == cmd) {

// Alert about an unsupported platform.

} else {

Runtime.getRuntime().exec(p);

}

Note: this code is untested and may not work. It's just an idea.

kevjavaa at 2007-7-21 21:51:49 > top of Java-index,Java Essentials,Java Programming...
# 18
I have thought of that , but this is not an option for me ;
Vladislava at 2007-7-21 21:51:49 > top of Java-index,Java Essentials,Java Programming...
# 19
Thanks for the reply Kevjava
Vladislava at 2007-7-21 21:51:49 > top of Java-index,Java Essentials,Java Programming...
# 20

The following works for me on RHEL4/64bit, running under Eclipse3.2.2 using Sun JDK 1.5:package javaforum;

import java.io.BufferedReader;

import java.io.BufferedWriter;

import java.io.InputStreamReader;

import java.io.OutputStreamWriter;

public class SudoTest {

public static void main(String[] args) throws Exception {

String[] cmd = new String[] { "sudo", "/sbin/service", "httpd", "start" };

System.out.print("Gimme root pwd plizkthxbai: ");

String rootPwd = new BufferedReader(new InputStreamReader(System.in)).readLine();

Process p = Runtime.getRuntime().exec(cmd);

BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(p.getOutputStream()));

bw.write(rootPwd, 0, rootPwd.length());

bw.newLine();

bw.flush();

}

}

Don't log in as root, it's bad - that's what sudo is for.

Grant

ggaineya at 2007-7-21 21:51:49 > top of Java-index,Java Essentials,Java Programming...
# 21

If you're going to use Grant's program then I suggest changing the prompt slightly, because sudo asks for the user's password rather than root's.

However, it strikes me that a better solution would be to make your snort executable suid, change its group ownership to a new group (e.g. "snort") with execution rights, then add people who need to run it to that group.

addgroup snort

chown root:snort `which snort`

chmod 4750 `which snort`

YAT_Archivista at 2007-7-21 21:51:49 > top of Java-index,Java Essentials,Java Programming...
# 22
the part i like is where he insecurely tries to run a program that is supposed to help you secure you're system.oooh the ironing.
prob.not.sola at 2007-7-21 21:51:49 > top of Java-index,Java Essentials,Java Programming...
# 23

> If you're going to use Grant's program then I suggest

> changing the prompt slightly, because sudo asks for

> the user's password rather than root's.

Oh...darn. Sorry, yes, true enough.

> However, it strikes me that a better solution would

> be to make your snort executable suid, change its

> group ownership to a new group (e.g. "snort") with

> execution rights, then add people who need to run it

> to that group.

Mmmm, sure, that would work. Guess I was stuck on "don't log in as root!", more than on elegant solutions to the actual problem :).

G

ggaineya at 2007-7-21 21:51:49 > top of Java-index,Java Essentials,Java Programming...
# 24

> However, it strikes me that a better solution would

> be to make your snort executable suid, change its

> group ownership to a new group (e.g. "snort") with

> execution rights, then add people who need to run it

> to that group.

> addgroup snort

> chown root:snort `which snort`

> chmod 4750 `which snort`

Minor nit: this is actually setgid, meaning that anyone who runs that file automatically gets to be part of the snort group. Thus, by doing that, you don't have to add people to the snort group. You can do what you're talking about (adding people to the snort group) and not have to setgid the script.

Just so the OP knows (and as prob.not.sol said above), this is potentially insecure, and could open up your system to security holes. You could be opened up to local (maybe even remote) privilege escalation threats.

kevjavaa at 2007-7-21 21:51:49 > top of Java-index,Java Essentials,Java Programming...