julien290

Q: Security: audit/trace of osascript call?

Hello,

 

I watch security of Mac systems and I wish to have an history of call to osascript, ideally a timestamp, which user, script or command argument used. Eventually pid and parent process/ppid would be nice too.

It could help to detect malicious activity on the mac.

 

is it possible?

 

Thanks

 

Note: working on El Capitan (10.11)

OS X El Capitan (10.11.6)

Posted on Sep 23, 2016 7:40 PM

Close

Q: Security: audit/trace of osascript call?

  • All replies
  • Helpful answers

  • by Camelot,

    Camelot Camelot Sep 23, 2016 8:29 PM in response to julien290
    Level 8 (47,290 points)
    Mac OS X
    Sep 23, 2016 8:29 PM in response to julien290

    There's nothing directly built-in that would do this, and I'm not sure quite what you'd gain since osascript isn't likely to be the primary attack vector... but it's your world.

     

    One idea I can imagine is replacing the /usr/bin/osascript binary with a shell wrapper that simply logs the invocation (with whatever other details you like) and then passes the input to the real osascript for execution. It's a little bit of security via obscurity, but it's all I can think of off-hand.

  • by etresoft,

    etresoft etresoft Sep 23, 2016 9:31 PM in response to julien290
    Level 7 (29,298 points)
    Mac OS X
    Sep 23, 2016 9:31 PM in response to julien290

    Hello julien290,

    I suggest using dtrace. I haven't used it for a couple of years. With SIP in El Capitan, it won't work on Apple processes, but it should work on 3rd party software. If not, you can always temporarily display SIP to play around.

     

    I can tell you that my own app EtreCheck uses this osascript method to elevate privileges. I don't want to deal with privileged helpers or actual privilege escalation. I can honestly say that EtreCheck never accesses a user's password. It just asks the Finder and osascript to do it instead.

     

    But, if you go to the EtreCheck github site (https://github.com/etresoft/EtreCheck) and clone it. The source code includes a little script that installs a fake piece of malware and then use EtreCheck to remove it. While doing this, you can play with various methods to detect EtreCheck's use of osascript. Good luck!

     

    Disclaimer: Although EtreCheck is free, there are other links on my site that could give me some form of compensation, financial or otherwise.

  • by dwbrecovery,

    dwbrecovery dwbrecovery Sep 24, 2016 4:11 AM in response to julien290
    Level 3 (589 points)
    Servers Enterprise
    Sep 24, 2016 4:11 AM in response to julien290

    Hi julien290,

    - Adding further, there is /usr/bin/opensnoop, which is written using dtrace, already in the OS.

    - It is restricted by SIP as explained by etresoft to 3rd party software.

     

    sudo /usr/bin/opensnoop 2>/dev/null   is a good example to start with.

     

    There is also execsnoop, iosnoop and rwsnoop but will require SIP to be disabled.

    Check their man pages.

     

    hth, cheers, dwbrecovery

  • by julien290,

    julien290 julien290 Sep 24, 2016 7:13 AM in response to dwbrecovery
    Level 1 (4 points)
    Mac OS X
    Sep 24, 2016 7:13 AM in response to dwbrecovery

    Hello

     

    Thanks all for the quick feedback. dtrace and *snoop tools are good option to investigate live case. I would also be curious about current state of dtrace on osx.

    Simplest option seems to be the wrapper (but need to be carefully written).

     

    Another thing I look into is using Google Santa (https://github.com/google/santa) and whitelist/blacklist applications.

     

    Thanks everyone!