0

I am connecting to a proftpd server via netcat

nc 10.10.239.150 21

Then I am doing some copy operations like "The mod_copy module implements SITE CPFR and SITE CPTO commands"

enter image description here

After "250 Copy successful" i want to exit this netcat connection and continue with the bash script.

I already tried following call, with CPFR and CPTO instructions outsourced to a msg.txt file

nc 10.10.115.253 21 < msg.txt

But still I dont know how to exit the netcat proftpd connection after successful proftpd operations.

Several tried EOF instructions are not understood by nc/proftpd: Only the CTRL C user input does the job, but this should be done automatically.

enter image description here

  • 1
    Does typing Control-D terminate it? If not, OS and version of netcat are you using? – Gordon Davisson Feb 21 '21 at 23:13
  • alternately, you could use lftp which supports site commands. – A.B Feb 21 '21 at 23:55
  • Read `man expect`. `expect` can automate some or all interactions with a program. – waltinator Feb 22 '21 at 00:40
  • @GordonDavisson CTRL C terminates , yes. But I want to run the whole script without user input. – florian.isopp Feb 22 '21 at 08:22
  • @A.B should be designed specifically for proftpd – florian.isopp Feb 22 '21 at 08:22
  • @florian.isopp Control-D (end of file), not Control-C (abort). But if you're trying to run it from a script, using an input file (like `< msg.txt`) or [here-document](https://unix.stackexchange.com/questions/232460/where-do-people-use-the-here-document-on-unix-systems/232466#232466) should work. Do they? – Gordon Davisson Feb 22 '21 at 09:51
  • @GordonDavisson I m already using an input file, but EOF or similar is not understood then from proftpd to exit the proftpd sess – florian.isopp Feb 22 '21 at 11:13
  • @florian.isopp proftpd is irrelevant; I expect `nc` to close its TCP connection when it reaches EOF of its input. If it's not, what version of `nc` are you using, and on what OS? – Gordon Davisson Feb 22 '21 at 11:20
  • it latest kali linux. nc -h is v1.10-46 . "EOF is not understood" (see updated screenshot in the question) – florian.isopp Feb 22 '21 at 12:09
  • nc is less specific to any FTP server than lftp is. In short lftp is more specific to ProFTPD than you'll ever achieve with nc. – A.B Feb 22 '21 at 12:52

1 Answers1

0

I don't have either a kali linux system or a ProFTPD server available to test with, so this is somewhat speculative, but I see a couple of things that might work.

First, a bit of explanation: it's really up to the client to terminate the connection to the server, not by sending a command, but by closing the TCP connection (technically, by sending a TCP/IP packet with the "fin" (finish) flag). So what's really needed here is to find a way to tell the nc program to close the connection after all operations are finished. And how you do that depends on the nc program (they're not all the same).

Possibility 1: some versions of nc need a -N option to tell them to close the TCP session after hitting EOF on their input. Check your man page to see if the version you have needs this.

Possibility 2: some versions have a -w option that lets you specify an "idle timeout" (in seconds) for the connection. Basically, if you specify nc -w 5 ... it'll close the connection after 5 seconds of inactivity. Again, check your man page.

Gordon Davisson
  • 4,360
  • 1
  • 18
  • 17