Welcome to Code Forum!

Join a community that supports you and your coding journey from day one. We strive to be a friendly, supportive community that empowers everyone to be better developers. By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    GIF shows where to locate </> in the thread and or post editor toolbar.
    To learn more about how to use our BBCode feature, review our "How to post your code into threads" here.

    Thank you, Code Forum.

How does the su program block automated input from bash?

null_reflections

Legendary Coder
As a novice programmer, I would think that this would put a password into the "su" command in linux and then validate the password:

echo <my-password> | su | echo

However, i've tried many variations of this (even using printf) and for some reason at best the password prints on the screen and then su asks me for the password again. I just thought it would be interesting to be able to automatically be superuser at startup, but unfortunately things are not always as straightforward as they seem! Doesn't piping mean converting one programs output into another program's input? I suppose i'd have to change "su" itself if I wanted this to work, does anyone know why?
 
Solution
D
Yes, piping works like this, and any normal Linux program will work when part of a pipe. But su is not normal ! For obvious security reasons, it demands that you physically type on the keyboard, reading the keyboard directly without echoing, rather than using the standard I/O streams. I believe that is functionality is actually built into the kernel. You may think of writing your own su, but there comes the inevitable moment you need to call setuid(0), and that will fail unless you are already root. You can't do this with normal programming tools, so unless you want to grab and tweak the Linux source code, you're out of luck.

Not sure what you mean if you say you If you want to "automatically be superuser at...
That wannabe hacker thing was always a joke anyway because if you're really good at infiltrating other people's stuff then you're probably just going to end up in prison or facing severe bodily injury, i kinda admire kevin mitnick for his ability to socially engineer yet after he got caught he just was giving lectures on pirating.

Wanting to know about security is pretty much a mandatory part of being a programmer nowadays, whatever fears there are of people who can figure out how things work are probably unwarranted, im much more afraid of people with legitamate authority than i am of haxer kids who call me racial/homophobic slurs on the internet. I resent the comparison, and this thread should probably be closed because the responses keep getting further away from the question.
Objectively false, sir. If you know how to do something, you don't need to flex online about it, like some of the script kiddies out there that all they are after is glory and infamy. I do hope you realize that being a sec engineer is indeed a thing that can get you paid well. A wise man once told me "A wise man is a man who knows when he does not know and is willing to humble thyself down and learn. A fool is a man who claims to know it all, but does not admit to the fact he knows not. A wise man is he who knows how and will not brag about. A fool is a man who brags about knowing but knows not how."
 
Objectively false, sir. If you know how to do something, you don't need to flex online about it, like some of the script kiddies out there that all they are after is glory and infamy. I do hope you realize that being a sec engineer is indeed a thing that can get you paid well. A wise man once told me "A wise man is a man who knows when he does not know and is willing to humble thyself down and learn. A fool is a man who claims to know it all, but does not admit to the fact he knows not. A wise man is he who knows how and will not brag about. A fool is a man who brags about knowing but knows not how."
Could you maybe clarify what is objectivily false in what i said? Is there even an objectively false when you see everything objective subjectively?

My personal goal is making software that has a practical use currently, i figured out the main aspects of the hacking/privacy thing pretty quickly just for the sake of learning what's possible...my interest is limited in "security", yet i do think it would be interesting to at least understand how viruses are made...the last thing i want is to have so many secrets that i can't relax. I personally/morally just tend to appreciate how to be creative and make interesting things, there's probably a whole lot more money in being a security professional than a scammer, ransomware/virus maker, or even someone who sells crack or stolen imformation on the internet.
 
Could you maybe clarify what is objectivily false in what i said? Is there even an objectively false when you see everything objective subjectively?

My personal goal is making software that has a practical use currently, i figured out the main aspects of the hacking/privacy thing pretty quickly just for the sake of learning what's possible...my interest is limited in "security", yet i do think it would be interesting to at least understand how viruses are made...the last thing i want is to have so many secrets that i can't relax. I personally/morally just tend to appreciate how to be creative and make interesting things, there's probably a whole lot more money in being a security professional than a scammer, ransomware/virus maker, or even someone who sells crack or stolen imformation on the internet.
Code:
 if you're really good at infiltrating other people's stuff then you're probably just going to end up in prison or facing severe bodily injury
This is the part I was signaling out. Just because you are good at something, doesn't mean you are gonna end up getting the bad end of the deal. If you know where to look, you will find plenty of legal opportunities.
 
Code:
 if you're really good at infiltrating other people's stuff then you're probably just going to end up in prison or facing severe bodily injury
This is the part I was signaling out. Just because you are good at something, doesn't mean you are gonna end up getting the bad end of the deal. If you know where to look, you will find plenty of legal opportunities.
You know, you can always select text that you're not responding to and hit the backspace button, i try to be painstakingly clear online since people flame so much and get offended over the silliest posts.
 
You know, you can always select text that you're not responding to and hit the backspace button, i try to be painstakingly clear online since people flame so much and get offended over the silliest posts.
True, but since the name of the game today is be as lazy as possible with my typing, copy + paste and surround with code block for added flair 😀
 
True, but since the name of the game today is be as lazy as possible with my typing, copy + paste and surround with code block for added flair 😀
Maybe you can tell me if i should learn vim or not then! I think it's honestly an impressive program, but the modes give me a headache and i just end up using insert mode to edit the text anyway. Ive spent hours trying to figure out how it makes text files easier or faster, but i always end up just feeling incredibly angry about it near the end. Ive really learned to appreciate the "simplicity" of nano...im putting that in quotes because its actually pretty complicated.
 
Maybe you can tell me if i should learn vim or not then! I think it's honestly an impressive program, but the modes give me a headache and i just end up using insert mode to edit the text anyway. Ive spent hours trying to figure out how it makes text files easier or faster, but i always end up just feeling incredibly angry about it near the end. Ive really learned to appreciate the "simplicity" of nano...im putting that in quotes because its actually pretty complicated.
Listen, it's great that you want to learn the ins and outs of things, but trust me lol, don't give yourself high blood pressure trying 😀. It's all a matter of preference. I personally stick to vi... at the end of the day they're all just text editors. All you're ever going to do with it is either write some notes, or write a script. As far as script output is concerned, you're always piping to an existing file or creating a new one. As far as searching/automated edits... sed, grep, etc. are always there. As far as being able to view a file's contents... well there's always
Code:
cat fileName
. Point being...pick a flavor and stick to it, or try em all out and decide which one better fits your needs
 
Listen, it's great that you want to learn the ins and outs of things, but trust me lol, don't give yourself high blood pressure trying 😀. It's all a matter of preference. I personally stick to vi... at the end of the day they're all just text editors. All you're ever going to do with it is either write some notes, or write a script. As far as script output is concerned, you're always piping to an existing file or creating a new one. As far as searching/automated edits... sed, grep, etc. are always there. As far as being able to view a file's contents... well there's always
Code:
cat fileName
. Point being...pick a flavor and stick to it, or try em all out and decide which one better fits your needs
Grep is pretty awesome tool, but those other text manipulation tools like sed, awk, pearl, kinda confuse me...my current plan is just to stick to sed and awk since those are very linux oriented...those together make bash very powerful. I've always been more interested in machine languages anyway, i just figure you might as well not learn those without command line and operating system knowledge.
 

Buy us a coffee!

Buy me a coffee.
Back
Top Bottom