![]() |
|
[Python] Eval - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [Python] Eval (/showthread.php?tid=5196016) |
Eval - CALL_ME_FORK - Mar 7, 2016 So I recently looking at some functions and I stumbled up on the Code evalYou see, I was confused on why I would use this instead of just plain print. Code eval('print("wow")')Code print("wow")Am I misusing this, or are there many other things you can do with this function? If you guys could also provide an example, that would be good too.✌ * - Goodies - Mar 7, 2016 Yes, those functions do the same thing. Try not to use exec() or eval() if you can afford it. Sometimes it may be cheeky and useful to do so. For example: PHP Code What this would do is create an instance of myClass() and set a bunch of instance variables. You would now be able to reference: PHP Code However, exec is not the best thing to use. You should be using setattr in that case. It works just the same. PHP Code But that's just an example of when it could exec() could actually be useful. But yeah, eval/exec should not be used, but this would be an example of eval(): PHP Code Even then, you should use hasattr to verify that it actually has the attribute and getattr to grab the value. * - Дɪɾsƿʟɪη - Mar 7, 2016 Yeah ive found use for eval in PHP before where I read in a dump of an array in a string format, and could easily use it as such as a quick hack since it was 1-time code: PHP Code Of course normally you'd try and avoid using eval since it can be dangerous. * - CALL_ME_FORK - Mar 9, 2016 So why is this system saying I tried in SQL injection when I was merely typing python code in the code function? Anyway I made a calculator in python with the eval function. I do have another question, why don't people use this function? It is so much easier with this than with a normal calculator. Also, why should I stay way from the eval and exec function? Does it create bugs or security issues? * - Goodies - Mar 9, 2016 (Mar 9, 2016 06:02 PM)CALL_ME_FORK Wrote: So why is this system saying I tried in SQL injection when I was merely typing python code in the code function? Because eval is dangerous.
* - Ƥeeka - Mar 9, 2016 I saw this in the thread recent posts and I quickly thought "uh oh". Try not to use eval, super dangerous. * - Stonky - Mar 10, 2016 (Mar 9, 2016 07:34 PM)Ƥeekaboi Wrote: I saw this in the thread recent posts and I quickly thought "uh oh". I back this. Eval isn't something you should use in production code. * - CALL_ME_FORK - Mar 10, 2016 Is eval dangerous because anyone can input anything in them? I was just using this for me anyway so I don't consider it too dangerous. * - Ƥeeka - Mar 10, 2016 (Mar 10, 2016 04:23 PM)CALL_ME_FORK Wrote: Is eval dangerous because anyone can input anything in them? Many hackers attempt to use eval because eval can evaluate any code from a input (base 64) * - CALL_ME_FORK - Mar 10, 2016 Ah, thank you! Someone can close this thread now. |