Detecting cron tasks run by another user

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












7















I am currently working through the Nebula challenges on exploit-exercises.com, and one of the challenges relies on a script being run by cron.



This is run by another user (flag03) and the user I am logged in as (level03) doesn't have privileges to run crontab -u flag03 to view the job.



The hint clearly indicates the script is run by cron. Additionally, it is the only script in the /home/flag03 directory, so we would likely investigate further.



However, if this was the real world, I wouldn't know that this script was being run by cron.



Therefore the question is, how would I detect that the task was being run from the perspective of an unprivileged user?



I have tried the following:



while true; do ps au | grep <scriptname> | grep -v grep; done;


This allows me to see processes that run for a significant length of time, but not ones that exit almost immediately. It also presumes I know the name of the script.



The specific environment is Ubuntu. I can't use apt-get, but I have access to gcc.



Any ideas?










share|improve this question



















  • 1





    Can you look at anything under /var/log/? Look for log messages about cron tasks.

    – slm
    Jun 6 '14 at 18:09











  • No, unfortunately no permissions or not relevant (grep -ri cron / or find / -name cron)

    – Cybergibbons
    Jun 6 '14 at 19:15















7















I am currently working through the Nebula challenges on exploit-exercises.com, and one of the challenges relies on a script being run by cron.



This is run by another user (flag03) and the user I am logged in as (level03) doesn't have privileges to run crontab -u flag03 to view the job.



The hint clearly indicates the script is run by cron. Additionally, it is the only script in the /home/flag03 directory, so we would likely investigate further.



However, if this was the real world, I wouldn't know that this script was being run by cron.



Therefore the question is, how would I detect that the task was being run from the perspective of an unprivileged user?



I have tried the following:



while true; do ps au | grep <scriptname> | grep -v grep; done;


This allows me to see processes that run for a significant length of time, but not ones that exit almost immediately. It also presumes I know the name of the script.



The specific environment is Ubuntu. I can't use apt-get, but I have access to gcc.



Any ideas?










share|improve this question



















  • 1





    Can you look at anything under /var/log/? Look for log messages about cron tasks.

    – slm
    Jun 6 '14 at 18:09











  • No, unfortunately no permissions or not relevant (grep -ri cron / or find / -name cron)

    – Cybergibbons
    Jun 6 '14 at 19:15













7












7








7


2






I am currently working through the Nebula challenges on exploit-exercises.com, and one of the challenges relies on a script being run by cron.



This is run by another user (flag03) and the user I am logged in as (level03) doesn't have privileges to run crontab -u flag03 to view the job.



The hint clearly indicates the script is run by cron. Additionally, it is the only script in the /home/flag03 directory, so we would likely investigate further.



However, if this was the real world, I wouldn't know that this script was being run by cron.



Therefore the question is, how would I detect that the task was being run from the perspective of an unprivileged user?



I have tried the following:



while true; do ps au | grep <scriptname> | grep -v grep; done;


This allows me to see processes that run for a significant length of time, but not ones that exit almost immediately. It also presumes I know the name of the script.



The specific environment is Ubuntu. I can't use apt-get, but I have access to gcc.



Any ideas?










share|improve this question
















I am currently working through the Nebula challenges on exploit-exercises.com, and one of the challenges relies on a script being run by cron.



This is run by another user (flag03) and the user I am logged in as (level03) doesn't have privileges to run crontab -u flag03 to view the job.



The hint clearly indicates the script is run by cron. Additionally, it is the only script in the /home/flag03 directory, so we would likely investigate further.



However, if this was the real world, I wouldn't know that this script was being run by cron.



Therefore the question is, how would I detect that the task was being run from the perspective of an unprivileged user?



I have tried the following:



while true; do ps au | grep <scriptname> | grep -v grep; done;


This allows me to see processes that run for a significant length of time, but not ones that exit almost immediately. It also presumes I know the name of the script.



The specific environment is Ubuntu. I can't use apt-get, but I have access to gcc.



Any ideas?







cron privileges






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 3 '18 at 18:50









José Castillo Lema

25119




25119










asked Jun 6 '14 at 7:05









CybergibbonsCybergibbons

1362




1362







  • 1





    Can you look at anything under /var/log/? Look for log messages about cron tasks.

    – slm
    Jun 6 '14 at 18:09











  • No, unfortunately no permissions or not relevant (grep -ri cron / or find / -name cron)

    – Cybergibbons
    Jun 6 '14 at 19:15












  • 1





    Can you look at anything under /var/log/? Look for log messages about cron tasks.

    – slm
    Jun 6 '14 at 18:09











  • No, unfortunately no permissions or not relevant (grep -ri cron / or find / -name cron)

    – Cybergibbons
    Jun 6 '14 at 19:15







1




1





Can you look at anything under /var/log/? Look for log messages about cron tasks.

– slm
Jun 6 '14 at 18:09





Can you look at anything under /var/log/? Look for log messages about cron tasks.

– slm
Jun 6 '14 at 18:09













No, unfortunately no permissions or not relevant (grep -ri cron / or find / -name cron)

– Cybergibbons
Jun 6 '14 at 19:15





No, unfortunately no permissions or not relevant (grep -ri cron / or find / -name cron)

– Cybergibbons
Jun 6 '14 at 19:15










6 Answers
6






active

oldest

votes


















0














Maybe using inotifywait in the /proc/[0-9]+ directories would let you have a better glimpse of short run processes.






share|improve this answer






























    0














    Looking at the challenge this method of attack would assume that you can run a script and watch what runs on the box, so I would write a script that simply does a dump of ps -eaf every couple of seconds, this would catch a cron, eventually, since crons run once every minute.



    This vector of attack would require you to watch for this script running, note the location of the script, and dig in deeper.






    share|improve this answer























    • Isn't that pretty much the one-liner I posted in the question?

      – Cybergibbons
      Jun 9 '14 at 8:13











    • @Cybergibbons - more or less. I'd modify the script slightly and there are other ways to watch for processes running, so if this wasn't successful in finding any cronjobs, I might dig in deeper with those.

      – slm
      Jun 9 '14 at 11:58


















    0














    In this specific case, the file is located on /var/spool/cron/crontabs/flag03, and you can read it with the nebula account.



    But level03 doesn't have enough privileges to access it.






    share|improve this answer






























      0














      Which version of Ubuntu? If it's using systemd, you could rely on the cron cgroup created by systemd I guess, as all processes started by cron will be a direct child.



      One of the option to get this information is to use the ps command with something like:



      ps -eo user,pid,cmd,unit | grep cron.service | grep flag03





      share|improve this answer

























      • Why does this not suffer from the same issue as the suggestion in the question i.e. short lived processes will be missed.

        – Cybergibbons
        Dec 20 '16 at 14:39











      • Indeed, but you could mix that with the idea from @piroux and add a inotify watch on the files in /sys/fs/cgroup/systemd/system.slice/cron.service/

        – Bigon
        Dec 20 '16 at 15:27


















      0














      You can't. The closest you can get is:



      inotifywait -m /home/flag03/script


      That won't show execution but it will show when script is opened or accessed.






      share|improve this answer






























        -1














        while true; do ps aux | egrep -v "grep|tail|aux" | tail -n 1; sleep 1; done





        share|improve this answer




















        • 3





          Give more info, it is a Q&A site and not a snippet sharing one.

          – peterh
          Dec 11 '16 at 7:52










        Your Answer








        StackExchange.ready(function()
        var channelOptions =
        tags: "".split(" "),
        id: "106"
        ;
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function()
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled)
        StackExchange.using("snippets", function()
        createEditor();
        );

        else
        createEditor();

        );

        function createEditor()
        StackExchange.prepareEditor(
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: false,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: null,
        bindNavPrevention: true,
        postfix: "",
        imageUploader:
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        ,
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        );



        );













        draft saved

        draft discarded


















        StackExchange.ready(
        function ()
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f134800%2fdetecting-cron-tasks-run-by-another-user%23new-answer', 'question_page');

        );

        Post as a guest















        Required, but never shown

























        6 Answers
        6






        active

        oldest

        votes








        6 Answers
        6






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        0














        Maybe using inotifywait in the /proc/[0-9]+ directories would let you have a better glimpse of short run processes.






        share|improve this answer



























          0














          Maybe using inotifywait in the /proc/[0-9]+ directories would let you have a better glimpse of short run processes.






          share|improve this answer

























            0












            0








            0







            Maybe using inotifywait in the /proc/[0-9]+ directories would let you have a better glimpse of short run processes.






            share|improve this answer













            Maybe using inotifywait in the /proc/[0-9]+ directories would let you have a better glimpse of short run processes.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jun 7 '14 at 11:34









            pirouxpiroux

            1




            1























                0














                Looking at the challenge this method of attack would assume that you can run a script and watch what runs on the box, so I would write a script that simply does a dump of ps -eaf every couple of seconds, this would catch a cron, eventually, since crons run once every minute.



                This vector of attack would require you to watch for this script running, note the location of the script, and dig in deeper.






                share|improve this answer























                • Isn't that pretty much the one-liner I posted in the question?

                  – Cybergibbons
                  Jun 9 '14 at 8:13











                • @Cybergibbons - more or less. I'd modify the script slightly and there are other ways to watch for processes running, so if this wasn't successful in finding any cronjobs, I might dig in deeper with those.

                  – slm
                  Jun 9 '14 at 11:58















                0














                Looking at the challenge this method of attack would assume that you can run a script and watch what runs on the box, so I would write a script that simply does a dump of ps -eaf every couple of seconds, this would catch a cron, eventually, since crons run once every minute.



                This vector of attack would require you to watch for this script running, note the location of the script, and dig in deeper.






                share|improve this answer























                • Isn't that pretty much the one-liner I posted in the question?

                  – Cybergibbons
                  Jun 9 '14 at 8:13











                • @Cybergibbons - more or less. I'd modify the script slightly and there are other ways to watch for processes running, so if this wasn't successful in finding any cronjobs, I might dig in deeper with those.

                  – slm
                  Jun 9 '14 at 11:58













                0












                0








                0







                Looking at the challenge this method of attack would assume that you can run a script and watch what runs on the box, so I would write a script that simply does a dump of ps -eaf every couple of seconds, this would catch a cron, eventually, since crons run once every minute.



                This vector of attack would require you to watch for this script running, note the location of the script, and dig in deeper.






                share|improve this answer













                Looking at the challenge this method of attack would assume that you can run a script and watch what runs on the box, so I would write a script that simply does a dump of ps -eaf every couple of seconds, this would catch a cron, eventually, since crons run once every minute.



                This vector of attack would require you to watch for this script running, note the location of the script, and dig in deeper.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jun 7 '14 at 12:31









                slmslm

                251k67529685




                251k67529685












                • Isn't that pretty much the one-liner I posted in the question?

                  – Cybergibbons
                  Jun 9 '14 at 8:13











                • @Cybergibbons - more or less. I'd modify the script slightly and there are other ways to watch for processes running, so if this wasn't successful in finding any cronjobs, I might dig in deeper with those.

                  – slm
                  Jun 9 '14 at 11:58

















                • Isn't that pretty much the one-liner I posted in the question?

                  – Cybergibbons
                  Jun 9 '14 at 8:13











                • @Cybergibbons - more or less. I'd modify the script slightly and there are other ways to watch for processes running, so if this wasn't successful in finding any cronjobs, I might dig in deeper with those.

                  – slm
                  Jun 9 '14 at 11:58
















                Isn't that pretty much the one-liner I posted in the question?

                – Cybergibbons
                Jun 9 '14 at 8:13





                Isn't that pretty much the one-liner I posted in the question?

                – Cybergibbons
                Jun 9 '14 at 8:13













                @Cybergibbons - more or less. I'd modify the script slightly and there are other ways to watch for processes running, so if this wasn't successful in finding any cronjobs, I might dig in deeper with those.

                – slm
                Jun 9 '14 at 11:58





                @Cybergibbons - more or less. I'd modify the script slightly and there are other ways to watch for processes running, so if this wasn't successful in finding any cronjobs, I might dig in deeper with those.

                – slm
                Jun 9 '14 at 11:58











                0














                In this specific case, the file is located on /var/spool/cron/crontabs/flag03, and you can read it with the nebula account.



                But level03 doesn't have enough privileges to access it.






                share|improve this answer



























                  0














                  In this specific case, the file is located on /var/spool/cron/crontabs/flag03, and you can read it with the nebula account.



                  But level03 doesn't have enough privileges to access it.






                  share|improve this answer

























                    0












                    0








                    0







                    In this specific case, the file is located on /var/spool/cron/crontabs/flag03, and you can read it with the nebula account.



                    But level03 doesn't have enough privileges to access it.






                    share|improve this answer













                    In this specific case, the file is located on /var/spool/cron/crontabs/flag03, and you can read it with the nebula account.



                    But level03 doesn't have enough privileges to access it.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Mar 12 '15 at 15:59









                    thiagowfxthiagowfx

                    736413




                    736413





















                        0














                        Which version of Ubuntu? If it's using systemd, you could rely on the cron cgroup created by systemd I guess, as all processes started by cron will be a direct child.



                        One of the option to get this information is to use the ps command with something like:



                        ps -eo user,pid,cmd,unit | grep cron.service | grep flag03





                        share|improve this answer

























                        • Why does this not suffer from the same issue as the suggestion in the question i.e. short lived processes will be missed.

                          – Cybergibbons
                          Dec 20 '16 at 14:39











                        • Indeed, but you could mix that with the idea from @piroux and add a inotify watch on the files in /sys/fs/cgroup/systemd/system.slice/cron.service/

                          – Bigon
                          Dec 20 '16 at 15:27















                        0














                        Which version of Ubuntu? If it's using systemd, you could rely on the cron cgroup created by systemd I guess, as all processes started by cron will be a direct child.



                        One of the option to get this information is to use the ps command with something like:



                        ps -eo user,pid,cmd,unit | grep cron.service | grep flag03





                        share|improve this answer

























                        • Why does this not suffer from the same issue as the suggestion in the question i.e. short lived processes will be missed.

                          – Cybergibbons
                          Dec 20 '16 at 14:39











                        • Indeed, but you could mix that with the idea from @piroux and add a inotify watch on the files in /sys/fs/cgroup/systemd/system.slice/cron.service/

                          – Bigon
                          Dec 20 '16 at 15:27













                        0












                        0








                        0







                        Which version of Ubuntu? If it's using systemd, you could rely on the cron cgroup created by systemd I guess, as all processes started by cron will be a direct child.



                        One of the option to get this information is to use the ps command with something like:



                        ps -eo user,pid,cmd,unit | grep cron.service | grep flag03





                        share|improve this answer















                        Which version of Ubuntu? If it's using systemd, you could rely on the cron cgroup created by systemd I guess, as all processes started by cron will be a direct child.



                        One of the option to get this information is to use the ps command with something like:



                        ps -eo user,pid,cmd,unit | grep cron.service | grep flag03






                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited Dec 11 '16 at 12:08









                        mazs

                        2,5921623




                        2,5921623










                        answered Dec 11 '16 at 11:35









                        BigonBigon

                        1,257713




                        1,257713












                        • Why does this not suffer from the same issue as the suggestion in the question i.e. short lived processes will be missed.

                          – Cybergibbons
                          Dec 20 '16 at 14:39











                        • Indeed, but you could mix that with the idea from @piroux and add a inotify watch on the files in /sys/fs/cgroup/systemd/system.slice/cron.service/

                          – Bigon
                          Dec 20 '16 at 15:27

















                        • Why does this not suffer from the same issue as the suggestion in the question i.e. short lived processes will be missed.

                          – Cybergibbons
                          Dec 20 '16 at 14:39











                        • Indeed, but you could mix that with the idea from @piroux and add a inotify watch on the files in /sys/fs/cgroup/systemd/system.slice/cron.service/

                          – Bigon
                          Dec 20 '16 at 15:27
















                        Why does this not suffer from the same issue as the suggestion in the question i.e. short lived processes will be missed.

                        – Cybergibbons
                        Dec 20 '16 at 14:39





                        Why does this not suffer from the same issue as the suggestion in the question i.e. short lived processes will be missed.

                        – Cybergibbons
                        Dec 20 '16 at 14:39













                        Indeed, but you could mix that with the idea from @piroux and add a inotify watch on the files in /sys/fs/cgroup/systemd/system.slice/cron.service/

                        – Bigon
                        Dec 20 '16 at 15:27





                        Indeed, but you could mix that with the idea from @piroux and add a inotify watch on the files in /sys/fs/cgroup/systemd/system.slice/cron.service/

                        – Bigon
                        Dec 20 '16 at 15:27











                        0














                        You can't. The closest you can get is:



                        inotifywait -m /home/flag03/script


                        That won't show execution but it will show when script is opened or accessed.






                        share|improve this answer



























                          0














                          You can't. The closest you can get is:



                          inotifywait -m /home/flag03/script


                          That won't show execution but it will show when script is opened or accessed.






                          share|improve this answer

























                            0












                            0








                            0







                            You can't. The closest you can get is:



                            inotifywait -m /home/flag03/script


                            That won't show execution but it will show when script is opened or accessed.






                            share|improve this answer













                            You can't. The closest you can get is:



                            inotifywait -m /home/flag03/script


                            That won't show execution but it will show when script is opened or accessed.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered May 3 '18 at 23:53









                            Mark WagnerMark Wagner

                            1,35667




                            1,35667





















                                -1














                                while true; do ps aux | egrep -v "grep|tail|aux" | tail -n 1; sleep 1; done





                                share|improve this answer




















                                • 3





                                  Give more info, it is a Q&A site and not a snippet sharing one.

                                  – peterh
                                  Dec 11 '16 at 7:52















                                -1














                                while true; do ps aux | egrep -v "grep|tail|aux" | tail -n 1; sleep 1; done





                                share|improve this answer




















                                • 3





                                  Give more info, it is a Q&A site and not a snippet sharing one.

                                  – peterh
                                  Dec 11 '16 at 7:52













                                -1












                                -1








                                -1







                                while true; do ps aux | egrep -v "grep|tail|aux" | tail -n 1; sleep 1; done





                                share|improve this answer















                                while true; do ps aux | egrep -v "grep|tail|aux" | tail -n 1; sleep 1; done






                                share|improve this answer














                                share|improve this answer



                                share|improve this answer








                                edited Dec 11 '16 at 20:36









                                slm

                                251k67529685




                                251k67529685










                                answered Dec 11 '16 at 5:44









                                RobRob

                                1




                                1







                                • 3





                                  Give more info, it is a Q&A site and not a snippet sharing one.

                                  – peterh
                                  Dec 11 '16 at 7:52












                                • 3





                                  Give more info, it is a Q&A site and not a snippet sharing one.

                                  – peterh
                                  Dec 11 '16 at 7:52







                                3




                                3





                                Give more info, it is a Q&A site and not a snippet sharing one.

                                – peterh
                                Dec 11 '16 at 7:52





                                Give more info, it is a Q&A site and not a snippet sharing one.

                                – peterh
                                Dec 11 '16 at 7:52

















                                draft saved

                                draft discarded
















































                                Thanks for contributing an answer to Unix & Linux Stack Exchange!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid


                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.

                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f134800%2fdetecting-cron-tasks-run-by-another-user%23new-answer', 'question_page');

                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown






                                Popular posts from this blog

                                Peggy Mitchell

                                Palaiologos

                                The Forum (Inglewood, California)