Score:0

Understanding the output of Cron

us flag

I'm having trouble understanding the output of cron. Suppose I have a cronjob that runs every five minutes:

*/5 * * * * root /home/user/Desktop/shell.sh

shell.sh has the following contents:

#!/bin/bash
echo "hello"
bash -i

I have the following questions:

  1. Where is the job run? E.g. is a new TTY process started where the shell script is run?

  2. Where is the output sent? I've read that the output is sent to the mail of the owner. Does this mean root gets a mail with the echo statement?

  3. What about the bash command? Does the script start a bash process in its controlling terminal session which remains running until the terminal session ends (at the end of the script?)?

  4. Suppose I have reversed the shell code in the above bash script and I run a nc listener on my computer. Will this mean that every 5 minutes I will receive a connection that closes as soon as the script finishes running?

Apologies for the numerous questions. I'm new to this stuff. Thanks.

Score:0
de flag
ob2

crontab is not exactly working like a classic shell.

  1. The job is run as root, but without any TTY. The command is run into a non-interactive environment, so bash -i probably returns an error or just closes once executed.

  2. Output is usually sent by mail. Ubuntu is usually shipped with a very minimal mail system called exim4. Look if file /var/mail/<your username> exists. You can try to read mail with:

    mail -u <your username>
    
  3. Because your script starts with #!/bin/bash, bash will be used, but this is not run in any terminal. Unless your script contains a loop, the process ends at the end of the script.

  4. I'm not sure I understand the use case with nc, but if you run nc from crontab to connect and send a message to your computer, nc and bash will end as soon the command is done.

Jhon Doe avatar
us flag
Hello for Q.3 I was referring to the bash -i command. For Q.4 I'm not running a listener in cron. Only the reverse shell is running in cron
de flag
ob2
Why didn't you described what you are trying to achieve. Are you looking for a way to take control of server with nc command ? Q3) bash -i will have no more effect, as explained, and cron is not run under interactive shell. Q4) I understood the listener is run on your computer and nc command is run a client and connect to your computer every 5 minutes.
Jhon Doe avatar
us flag
Thank for the reply. So I have nc -lvnp 8000 running on computer A and suppose on computer B I have a cron job that executes with root. If I input a reverse shell code in the cron job will I have a reverse shell connection every 5 minutes that ends every time the script finishes running?
de flag
ob2
I'm not sure how should work the reverse shell code, do you already done it without cron by running the commands manually ?
Jhon Doe avatar
us flag
Hey it's fine. Ive decide to ask a more specific question on the information security stackexchange. But thanks for your answer anyway.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.