Thread: Need help, is this code malicious ?

  1. #1
    Registered User
    Join Date
    Dec 2010
    Posts
    3

    Need help, is this code malicious ?

    Im taking a security class that I was told had nothing to do with programing. Of course the entire semester goes by and there is no programing at all. Until the final ...

    Can someone please help me out with this question?

    http://cwlmiami.com/question.JPG
    Last edited by miamitj; 12-10-2010 at 11:53 AM.

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Quote Originally Posted by miamitj View Post
    Im taking a security class that I was told had nothing to do with programing. Of course the entire semester goes by and there is no programing at all. Until the final ...

    Can someone please help me out with this question?

    http://cwlmiami.com/question.JPG
    Well, considering that the code described doesn't even *compile*, it's completely harmless! What book is that, anyway?
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    Registered User
    Join Date
    Dec 2010
    Posts
    3
    Quote Originally Posted by Sebastiani View Post
    Well, considering that the code described doesn't even *compile*, it's completely harmless! What book is that, anyway?
    William Stallings -- Computer Security -- Principles and Practice.

    Im guessing the first one is suppose to print. What is the second one suppose to do?

  4. #4
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Quote Originally Posted by miamitj View Post
    William Stallings -- Computer Security -- Principles and Practice.

    Im guessing the first one is suppose to print. What is the second one suppose to do?
    Who knows what it's "supposed to do" - it's nonsense.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  5. #5
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    As for the first one, yes, it looks like it's supposed to print, but begin, print and end are not keywords in C. I would almost say it was Pascal, given the begin, end, (* and *), but the output command in Pascal is write, not print.

    As for the second example: The first printf is totally bogus syntax. The for loop looks like it's trying to print the numeric value of each character in t, and the final printf prints out the string representation of t, but there's no terminating null (unless it's part of the "and so on..."), so it may print all kinds of bogus info. Note that t is never declared anywhere.

    I would say the relevance is that, if a hacker is so stupid he can't even compile a program, you don't have to worry about him.

  6. #6
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by anduril462 View Post
    As for the first one, yes, it looks like it's supposed to print, but begin, print and end are not keywords in C. I would almost say it was Pascal, given the begin, end, (* and *), but the output command in Pascal is write, not print.

    As for the second example: The first printf is totally bogus syntax. The for loop looks like it's trying to print the numeric value of each character in t, and the final printf prints out the string representation of t, but there's no terminating null (unless it's part of the "and so on..."), so it may print all kinds of bogus info. Note that t is never declared anywhere.

    I would say the relevance is that, if a hacker is so stupid he can't even compile a program, you don't have to worry about him.
    Think about it guys... If you were teaching a course on computer security, would you let your students --half of whom you know are taking the course to learn how to get around security-- within half a mile of working malicious code?

  7. #7
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Sure I would, and so did my professor. I took a security course when I did my undergrad. We did all sorts of code analysis, discussing buffer overflows and issues with signed/unsigned stuff. We even had to write a program to insert a "malicious" printf statement using buffer overflows for some RPC stuff in a fake service the prof wrote.

    Most of the code that will be covered in a security course is "in the style of" malicious code, but can't really harm anything itself. Things like examples of buffer overflows changing a return value in a program that doesn't actually do anything on a system is innocuous, but demonstrates the principles quite well. The actual implementation of these things is incredibly complex, requiring detailed knowledge of the system to be attacked, compiler used to compile the program, etc and is probably beyond the grasp of most university students.

  8. #8
    Registered User
    Join Date
    Dec 2010
    Posts
    3
    Quote Originally Posted by CommonTater View Post
    Think about it guys... If you were teaching a course on computer security, would you let your students --half of whom you know are taking the course to learn how to get around security-- within half a mile of working malicious code?
    This is for my Masters. The people in this class are paying WAY to much $$$ to be taking a class just to get around security. I'm sure it would be easier to Google code then deal with a class like this.

  9. #9
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by miamitj View Post
    William Stallings -- Computer Security -- Principles and Practice.
    Thanks, I'll be sure to stay the hell away from that book (unless I need a good laugh).
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 23
    Last Post: 04-20-2009, 07:35 AM
  2. Extended ASCII Characters in an RTF Control
    By JustMax in forum C Programming
    Replies: 18
    Last Post: 04-03-2009, 08:20 PM
  3. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 06:05 PM