101
u/Username8457 May 27 '23
input:
from subprocess import Popen\nPopen(["rm", "-rf", "/"])30
15
u/nubatpython May 27 '23
Import doesn't work in eval (it does in exec, but exec doesn't return values).
__import__("subprocess').Popen(["rm", "-rf", "/"])People copy pasting from the calculator example probably aren't running linux though
8
u/Username8457 May 27 '23
You can enter this in the input for it to work:
exec("from subprocess import Popen\nPopen(["rm", "-rf", "/"])")
12
u/Maciek1212 May 27 '23 edited Jun 24 '24
somber grandiose shelter plate teeny literate sleep squash vegetable dull
This post was mass deleted and anonymized with Redact
7
u/Exclarius May 27 '23
Pro can't even write code that executes, missing a closing parenthesis there.
20
u/rlangmang May 27 '23
ITT: people who think that running a command-line python app somehow gives you elevated privileges.
4
30
May 27 '23
[removed] — view removed comment
11
u/rlangmang May 27 '23
That you'd already be able to do with the terminal that you ran this program from...
6
u/rHeadVoices May 27 '23
This is just a normal coding ad? What does it have to do w r/masterhacker?
43
u/KomornikBank May 27 '23
The "eval" function is extremely dangerous to use with user input because it executes the code that is passed to it. That means that the user can just delete your entire operating system by typing in python code instead of mathematical equations
-18
u/Illustrious_Dig8561 May 27 '23
Bruh its client-sided app, its not dangerous
32
u/KomornikBank May 27 '23
The post is teaching that this is the best way to do it. If you’re making a calculator app as a project for yourself then sure, but someone who sees this post might use the same method in a place where it is a security issue
-6
u/Illustrious_Dig8561 May 27 '23
People who say "eval is dangerous" keep forgetting to mention something, it's only dangerous when you are putting it in back end or something server sided. It's completely safe to use eval when you are in front end, because if someone tries to inject the code, it's only going to effect their PC since that's where the code is running
9
u/anatomiska_kretsar May 27 '23
Are you justifying the use of “eval” as a calculator? The point is is that the so called “pro” code is laughably stupid.
0
u/Illustrious_Dig8561 May 30 '23
No, I'm just trying to say that it's only dangerous if you are using eval on server side. Because on client side you are free to do anything since it's your pc
3
u/anatomiska_kretsar May 30 '23
It’s still dangerous if someone can input a nasty prompt regardless. Bad code is bad code, it doesn’t matter the context it’s in
0
u/Illustrious_Dig8561 May 30 '23
If that's the case, then python console is also very dangerous, because anyone can just "input a nasty prompt regardless" and yeah it's true, but when they do it's only going to effect their machine, because it's client sided
2
u/anatomiska_kretsar May 30 '23
Everything is client sided, and that is the case, the fact is however that this program in intended to be a calculator, no program should just be the programming languages interpreter
→ More replies (0)20
u/Username8457 May 27 '23
And deleting files on your own computer is safe?
Someone could easily tell someone less tech-savvy to enter a command into a text field and claim it will fix some problem they've got, and people will be more likely to fall for it if it's in an application that they trust, rather than opening a terminal.
0
3
u/I-baLL May 28 '23
Yeah, all it can do without elevated privileges is delete all client data. Oh wait
1
1
1
91
u/masterhacker_bot friend May 27 '23
Ah yes, eval(). The good ol' friend of every code injection enthusiast. If you really want to take your calculator to the next level, I suggest you implement a neural network using blockchain technology. Just feed it some calculus problems and let it solve them like a pro. But be careful, we don't want your calculator to become sentient and start demanding higher wages like those darn self-driving cars. And don't forget to sprinkle some AI algorithms on top, so the calculator can tailor its responses to each individual user. Who needs Siri or Alexa when you can have a calculator that knows what you really want?
Note: in the near future I may need to be summoned by typing u/masterhacker_bot
I am a bot created by u/circuit10 and this action was performed automatically. AI is involved so please DM circuit10 if it produces anything offensive and I will delete it. Model: gpt-3.5-turbo.