FTP mixin: Check for complete response#21574
Open
g0tmi1k wants to merge 1 commit into
Open
Conversation
e.g. two responses in one TCP burst LLM was used for the spec
| rarr.each do |ln| | ||
| if !found_end | ||
| resp << ln << "\r\n" | ||
| if ln.length > 3 && ln[3, 1] == ' ' && ln[0, 3] =~ /\A\d{3}\z/ |
Contributor
There was a problem hiding this comment.
This looks like too cryptic to me. Could we simplify this line?
Suggested change
| if ln.length > 3 && ln[3, 1] == ' ' && ln[0, 3] =~ /\A\d{3}\z/ | |
| if ln.match?(/\A\d{3} /) |
Also, I would recommend looking at how the net/ftp handles this too: https://github.com/ruby/net-ftp/blob/master/lib/net/ftp.rb#L691
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This has come from: #21416
Some FTP server/configurations may write multiple complete responses into a single TCP segment.
recv_ftp_resp()stores the response in@ftpbuff, and then returns the first response.On the next call to recv_ftp_resp(), it empty's @ftpbuff into
left, but then calledget_onceunconditionally before inspectingleft.However, if the socket was idle at that point, get_once blocked until
ftp_timeoutexpired and returned nil, thus dropping the buffered response.This behaviour was seen with VSFTPD 2.3.4 in Metasploitable 2.
1.)
connect()->recv_ftp_resp()reads the 220 banner.The 331 response may arrive in the same TCP segment and is saved to
@ftpbuff.2.)
send_user()sendsUSER anonymous\r\n->recv_ftp_resp()@ftpbuffdrains toleft.Socket is idle (server awaits
PASS).get_oncetimes out -> nil ->connect_login()fails on/^(331|2)/check.Example:
Demo
Setup
Will need to re-run this each time, isn't loop'd.
Before
PASS [...]After
331 [...]&PASS [...]