1

I want to scp a .sh script to /dev/shm but it gives me

error: unexpected filename: .

I don't even see where there would be a lone . in either the script or the directory.

The full command was:

scp -r /opt/PEAS/linPEAS/linpeas.sh [email protected]: /dev/shm

(it's from a newbie hacking CTF-type game). I tried adding $(pwd) as suggested in other threads but to no avail.

Kamil Maciorowski
  • 69,815
  • 22
  • 136
  • 202
  • 1
    What's the goal here? copy `linpeas.sh` to the remote host? If so, the format is `${user}@${host}:${path}`, so remove that space before `/dev/shm`! ("_no path_" is interpreted as "_here_" or `.`). – Attie Jun 08 '22 at 21:57
  • Oh man, that's it! Thank youuuu – user1699544 Jun 09 '22 at 08:05

2 Answers2

3

scp like cp supports copying from multiple sources to a single target directory. In your command

scp -r /opt/PEAS/linPEAS/linpeas.sh [email protected]: /dev/shm

/opt/PEAS/linPEAS/linpeas.sh and [email protected]: are sources, /dev/shm is a (local) target. For local copying scp falls back to cp. Your command is roughly equivalent to:

cp -r /opt/PEAS/linPEAS/linpeas.sh /dev/shm
scp -r [email protected]: /dev/shm

and [email protected]: in the latter is equivalent to [email protected]:. and means ". (the current working directory) after ssh-ing to [email protected]".

While totally local cp -r . /dev/shm (or even scp -r . /dev/shm) may work, scp refuses to download a remote file named .. (I mean the legacy scp which uses SCP, not SFTP. See "preliminary note" in this answer of mine. It appears your scp uses SCP. My tests indicate scp using SFTP can download . from a server.)


With that being said, I suspect maybe you don't want local /dev/shm as the target directory. Maybe you want:

scp -r /opt/PEAS/linPEAS/linpeas.sh [email protected]:/dev/shm

where [email protected]:/dev/shm is a remote target, it means /dev/shm on 10.10.87.42. The above command will upload local linpeas.sh to remote /dev/shm. You don't really need -r, unless linpeas.sh is a directory.

Kamil Maciorowski
  • 69,815
  • 22
  • 136
  • 202
  • Thanks so much for that detailed explanation. Learned a lot today! It was the bloody space in the end ... But your explanation definitely made me appreciate and think more deeply about unexpected behaviors. There really is a reason why I should be more careful with commands and learn why it does certain things. "The computer does what you tell it, not what you want it to do" I was reminded of that right now. – user1699544 Jun 09 '22 at 08:12
0

/dev/shm is the shared-memory of Linux, that can be addressed as a disk. It is not an SSH server.

You should be using:

scp -r /opt/PEAS/linPEAS/linpeas.sh /dev/shm

But I'm not sure that this is what you wish to do. The size is limited, and the data would be lost after a reboot.

See for example What Is /dev/shm And Its Practical Usage.

harrymc
  • 455,459
  • 31
  • 526
  • 924
  • Looks like I don't understand the concept of shared memory even after reading that article. The guy in the tutorial did it like this. Though on second glance I see that he didn't have a space between [email protected]: and /dev/shm. Would that change the behavior? I probably need to read up on fundamentals before messing around in these CTFs. Thanks though! – user1699544 Jun 08 '22 at 20:33
  • If my answer was helpful, please consider marking it as accepted (click the ✔ sign). – harrymc Jun 08 '22 at 20:51