����JFIFXX�����    $.' ",#(7),01444'9=82<.342  2!!22222222222222222222222222222222222222222222222222����"��4�� ���,�PG"Z_�4�˷����kjز�Z�,F+��_z�,�© �����zh6�٨�ic�fu���#ډb���_�N�?��wQ���5-�~�I���8����TK<5o�Iv-�����k�_U_�����~b�M��d����Ӝ�U�Hh��?]��E�w��Q���k�{��_}qFW7HTՑ��Y��F�?_�'ϔ��_�Ջt��=||I ��6�έ"�����D���/[�k�9���Y�8ds|\���Ҿp6�Ҵ���]��.����6�z<�v��@]�i%��$j��~�g��J>��no����pM[me�i$[����s�o�ᘨ�˸ nɜG-�ĨU�ycP�3.DB�li�;��hj���x7Z^�N�h������N3u{�:j�x�힞��#M&��jL P@_���� P��&��o8������9�����@Sz6�t7#O�ߋ �s}Yf�T���lmr����Z)'N��k�۞p����w\�Tȯ?�8`�O��i{wﭹW�[�r�� ��Q4F�׊���3m&L�=��h3����z~��#�\�l :�F,j@�� ʱ�wQT����8�"kJO���6�֚l����}���R�>ډK���]��y����&����p�}b��;N�1�m�r$�|��7�>e�@B�TM*-iH��g�D�)� E�m�|�ؘbҗ�a��Ҿ����t4���o���G��*oCN�rP���Q��@z,|?W[0�����:�n,jWiE��W��$~/�hp\��?��{(�0���+�Y8rΟ�+����>S-S����VN;�}�s?.����� w�9��˟<���Mq4�Wv'��{)0�1mB��V����W[�����8�/<� �%���wT^�5���b��)iM� pg�N�&ݝ��VO~�q���u���9� ����!��J27����$O-���! �:�%H��� ـ����y�ΠM=t{!S�� oK8������t<����è:a������[�����ա�H���~��w��Qz`�po�^ ����Q��n� �,uu�C�$ ^���,������8�#��:�6��e�|~���!�3�3.�\0��q��o�4`.|� ����y�Q�`~;�d�ׯ,��O�Zw�������`73�v�܋�<���Ȏ�� ـ4k��5�K�a�u�=9Yd��$>x�A�&�� j0� ���vF��� Y�|�y��� ~�6�@c��1vOp�Ig����4��l�OD���L����� R���c���j�_�uX6��3?nk��Wy�f;^*B� ��@�~a�`��Eu������+���6�L��.ü>��}y���}_�O�6�͐�:�YrG�X��kG�����l^w���~㒶sy��Iu�!� W ��X��N�7BV��O��!X�2����wvG�R�f�T#�����t�/?���%8�^�W�aT��G�cL�M���I��(J����1~�8�?aT ���]����AS�E��(��*E}� 2��#I/�׍qz��^t�̔���b�Yz4x���t�){ OH��+(E��A&�N�������XT��o��"�XC��'���)}�J�z�p� ��~5�}�^����+�6����w��c��Q�|Lp�d�H��}�(�.|����k��c4^�"�����Z?ȕ ��a<�L�!039C� �Eu�C�F�Ew�ç ;�n?�*o���B�8�bʝ���'#Rqf���M}7����]����s2tcS{�\icTx;�\��7K���P���ʇ Z O-��~��c>"��?�������P��E��O�8��@�8��G��Q�g�a�Վ���󁶠�䧘��_%#r�>�1�z�a��eb��qcPѵ��n���#L��� =��׀t� L�7�`��V���A{�C:�g���e@�w1 Xp3�c3�ġ����p��M"'-�@n4���fG��B3�DJ�8[Jo�ߐ���gK)ƛ��$���� ���8�3�����+���� �����6�ʻ���� ���S�kI�*KZlT _`���?��K����QK�d����B`�s}�>���`��*�>��,*@J�d�oF*����弝��O}�k��s��]��y�ߘ��c1G�V���<=�7��7����6�q�PT��tXԀ�!9*4�4Tހ3XΛex�46���Y��D ����� �BdemDa����\�_l,��G�/���֌7���Y�](�xTt^%�GE�����4�}bT���ڹ�����;Y)���B�Q��u��>J/J �⮶.�XԄ��j�ݳ�+E��d ��r�5�_D�1 ��o�� �B�x�΢�#���<��W�����8���R6�@g�M�.��� dr�D��>(otU��@x=��~v���2� ӣ�d�oBd��3�eO�6�㣷�����ݜ6��6Y��Qz`��S��{���\P�~z m5{J/L��1������<�e�ͅPu�b�]�ϔ���'������f�b� Zpw��c`"��i���BD@:)ִ�:�]��hv�E�w���T�l��P���"Ju�}��وV J��G6��. J/�Qgl߭�e�����@�z�Zev2u�)]կ�����7x���s�M�-<ɯ�c��r�v�����@��$�ޮ}lk���a���'����>x��O\�ZFu>�����ck#��&:��`�$�ai�>2Δ����l���oF[h��lE�ܺ�Πk:)���`�� $[6�����9�����kOw�\|���8}������ބ:��񶐕��I�A1/�=�2[�,�!��.}gN#�u����b��� ~��݊��}34q����d�E��Lc��$��"�[q�U�硬g^��%B �z���r�pJ�ru%v\h1Y�ne`ǥ:g���pQM~�^�Xi� ��`S�:V29.�P���V�?B�k�� AEvw%�_�9C�Q����wKekPؠ�\�;Io d�{ ߞo�c1eP����\� `����E=���@K<�Y���eڼ�J���w����{av�F�'�M�@/J��+9p���|]�����Iw &`��8���&M�hg��[�{��Xj��%��Ӓ�$��(����ʹN���<>�I���RY���K2�NPlL�ɀ)��&e����B+ь����( � �JTx���_?EZ� }@ 6�U���뙢ط�z��dWI�n` D����噥�[��uV��"�G&Ú����2g�}&m��?ċ�"����Om#��������� ��{�ON��"S�X��Ne��ysQ���@Fn��Vg���dX�~nj�]J�<�K]:��FW��b�������62�=��5f����JKw��bf�X�55��~J �%^����:�-�QIE��P��v�nZum� z � ~ə ���� ���ة����;�f��\v���g�8�1��f24;�V���ǔ�)����9���1\��c��v�/'Ƞ�w�������$�4�R-��t���� e�6�/�ġ �̕Ecy�J���u�B���<�W�ַ~�w[B1L۲�-JS΂�{���΃������A��20�c#��@ 0!1@AP"#2Q`$3V�%45a6�FRUq��� ����^7ׅ,$n�������+��F�`��2X'��0vM��p�L=������5��8������u�p~���.�`r�����\���O��,ư�0oS ��_�M�����l���4�kv\JSd���x���SW�<��Ae�IX����������$I���w�:S���y���›R��9�Q[���,�5�;�@]�%���u�@ *ro�lbI �� ��+���%m:�͇ZV�����u�̉����θau<�fc�.����{�4Ա� �Q����*�Sm��8\ujqs]{kN���)qO�y�_*dJ�b�7���yQqI&9�ԌK!�M}�R�;������S�T���1���i[U�ɵz�]��U)V�S6���3$K{�ߊ<�(� E]Զ[ǼENg�����'�\?#)Dkf��J���o��v���'�%ƞ�&K�u�!��b�35LX�Ϸ��63$K�a�;�9>,R��W��3�3� d�JeTYE.Mϧ��-�o�j3+y��y^�c�������VO�9NV\nd�1 ��!͕_)a�v;����թ�M�lWR1��)El��P;��yوÏ�u 3�k�5Pr6<�⒲l�!˞*��u־�n�!�l:����UNW ��%��Chx8vL'��X�@��*��)���̮��ˍ��� ���D-M�+J�U�kvK����+�x8��cY������?�Ԡ��~3mo��|�u@[XeY�C�\Kp�x8�oC�C�&����N�~3-H���� ��MX�s�u<`���~"WL��$8ξ��3���a�)|:@�m�\���^�`�@ҷ)�5p+��6���p�%i)P M���ngc�����#0Aruz���RL+xSS?���ʮ}()#�t��mˇ!��0}}y����<�e� �-ή�Ԩ��X������ MF���ԙ~l L.3���}�V뽺�v�����멬��Nl�)�2����^�Iq��a��M��qG��T�����c3#������3U�Ǎ���}��לS�|qa��ڃ�+���-��2�f����/��bz��ڐ�� �ݼ[2�ç����k�X�2�* �Z�d���J�G����M*9W���s{��w���T��x��y,�in�O�v��]���n����P�$�JB@=4�OTI�n��e�22a\����q�d���%�$��(���:���: /*�K[PR�fr\nڙdN���F�n�$�4�[�� U�zƶ����� �mʋ���,�ao�u 3�z� �x��Kn����\[��VFmbE;�_U��&V�Gg�]L�۪&#n%�$ɯ�dG���D�TI=�%+AB�Ru#��b4�1�»x�cs�YzڙJG��f��Il��d�eF'T� iA��T���uC�$����Y��H?����[!G`}���ͪ� �纤Hv\������j�Ex�K���!���OiƸ�Yj�+u-<���'q����uN�*�r\��+�]���<�wOZ.fp�ێ��,-*)V?j-kÊ#�`�r��dV����(�ݽBk�����G�ƛk�QmUڗe��Z���f}|����8�8��a���i��3'J�����~G_�^���d�8w������ R�`(�~�.��u���l�s+g�bv���W���lGc}��u���afE~1�Ue������Z�0�8�=e�� f@/�jqEKQQ�J��oN��J���W5~M>$6�Lt�;$ʳ{���^��6�{����v6���ķܰg�V�cnn �~z�x�«�,2�u�?cE+Ș�H؎�%�Za�)���X>uW�Tz�Nyo����s���FQƤ��$��*�&�LLXL)�1�" L��eO��ɟ�9=���:t��Z���c��Ž���Y?�ӭV�wv�~,Y��r�ۗ�|�y��GaF�����C�����.�+� ���v1���fήJ�����]�S��T��B��n5sW}y�$��~z�'�c ��8 ��� ,! �p��VN�S��N�N�q��y8z˱�A��4��*��'������2n<�s���^ǧ˭P�Jޮɏ�U�G�L�J�*#��<�V��t7�8����TĜ>��i}K%,���)[��z�21z ?�N�i�n1?T�I�R#��m-�����������������1����lA�`��fT5+��ܐ�c�q՝��ʐ��,���3�f2U�եmab��#ŠdQ�y>\��)�SLY����w#��.���ʑ�f��� ,"+�w�~�N�'�c�O�3F�������N<���)j��&��,-� �љ���֊�_�zS���TǦ����w�>��?�������n��U仆�V���e�����0���$�C�d���rP �m�׈e�Xm�Vu� �L��.�bֹ��� �[Դaզ���*��\y�8�Է:�Ez\�0�Kq�C b��̘��cө���Q��=0Y��s�N��S.���3.���O�o:���#���v7�[#߫ ��5�܎�L���Er4���9n��COWlG�^��0k�%<���ZB���aB_���������'=��{i�v�l�$�uC���mƎҝ{�c㱼�y]���W�i ��ߧc��m�H� m�"�"�����;Y�ߝ�Z�Ǔ�����:S#��|}�y�,/k�Ld� TA�(�AI$+I3��;Y*���Z��}|��ӧO��d�v��..#:n��f>�>���ȶI�TX��� 8��y����"d�R�|�)0���=���n4��6ⲑ�+��r<�O�܂~zh�z����7ܓ�HH�Ga롏���nCo�>������a ���~]���R���̲c?�6(�q�;5%� |�uj�~z8R=X��I�V=�|{v�Gj\gc��q����z�؋%M�ߍ����1y��#��@f^���^�>N�����#x#۹��6�Y~�?�dfPO��{��P�4��V��u1E1J �*|���%���JN��`eWu�zk M6���q t[�� ��g�G���v��WIG��u_ft����5�j�"�Y�:T��ɐ���*�;� e5���4����q$C��2d�}���� _S�L#m�Yp��O�.�C�;��c����Hi#֩%+) �Ӎ��ƲV���SYź��g |���tj��3�8���r|���V��1#;.SQ�A[���S������#���`n�+���$��$I �P\[�@�s��(�ED�z���P��])8�G#��0B��[ى��X�II�q<��9�~[Z멜�Z�⊔IWU&A>�P~�#��dp<�?����7���c��'~���5 ��+$���lx@�M�dm��n<=e�dyX��?{�|Aef ,|n3�<~z�ƃ�uۧ�����P��Y,�ӥQ�*g�#먙R�\���;T��i,��[9Qi歉����c>]9�� ��"�c��P�� �Md?٥��If�ت�u��k��/����F��9�c*9��Ǎ:�ØF���z�n*�@|I�ށ9����N3{'��[�'ͬ�Ҳ4��#}��!�V� Fu��,�,mTIk���v C�7v���B�6k�T9��1�*l� '~��ƞF��lU��'�M ����][ΩũJ_�{�i�I�n��$���L�� j��O�dx�����kza۪��#�E��Cl����x˘�o�����V���ɞ�ljr��)�/,�߬h�L��#��^��L�ф�,íMƁe�̩�NB�L�����iL����q�}��(��q��6IçJ$�W�E$��:������=#����(�K�B����zђ <��K(�N�۫K�w��^O{!����)�H���>x�������lx�?>Պ�+�>�W���,Ly!_�D���Ō�l���Q�!�[ �S����J��1��Ɛ�Y}��b,+�Lo�x�ɓ)����=�y�oh�@�꥟/��I��ѭ=��P�y9��� �ۍYӘ�e+�p�Jnϱ?V\SO%�(�t� ���=?MR�[Ș�����d�/ ��n�l��B�7j� ��!�;ӥ�/�[-���A�>�dN�sLj ��,ɪv��=1c�.SQ�O3�U���ƀ�ܽ�E����������̻��9G�ϷD�7(�}��Ävӌ\�y�_0[w ���<΍>����a_��[0+�L��F.�޺��f�>oN�T����q;���y\��bՃ��y�jH�<|q-eɏ�_?_9+P���Hp$�����[ux�K w�Mw��N�ی'$Y2�=��q���KB��P��~������Yul:�[<����F1�2�O���5=d����]Y�sw:���Ϯ���E��j,_Q��X��z`H1,#II ��d�wr��P˂@�ZJV����y$�\y�{}��^~���[:N����ߌ�U�������O��d�����ؾe��${p>G��3c���Ė�lʌ�� ת��[��`ϱ�-W����dg�I��ig2��� ��}s ��ؤ(%#sS@���~���3�X�nRG�~\jc3�v��ӍL��M[JB�T��s3}��j�Nʖ��W����;7��ç?=X�F=-�=����q�ߚ���#���='�c��7���ڑW�I(O+=:uxq�������������e2�zi+�kuG�R��������0�&e�n���iT^J����~\jy���p'dtG��s����O��3����9* �b#Ɋ�� p������[Bws�T�>d4�ۧs���nv�n���U���_�~,�v����ƜJ1��s�� �QIz��)�(lv8M���U=�;����56��G���s#�K���MP�=��LvyGd��}�VwWBF�'�à �?MH�U�g2�� ����!�p�7Q��j��ڴ����=��j�u��� Jn�A s���uM������e��Ɔ�Ҕ�!)'��8Ϣ�ٔ��ޝ(��Vp���צ֖d=�IC�J�Ǡ{q������kԭ�߸���i��@K����u�|�p=..�*+����x�����z[Aqġ#s2a�Ɗ���RR�)*HRsi�~�a &f��M��P����-K�L@��Z��Xy�'x�{}��Zm+���:�)�) IJ�-i�u���� ���ܒH��'�L(7�y�GӜq���� j��� 6ߌg1�g�o���,kر���tY�?W,���p���e���f�OQS��!K�۟cҒA�|ս�j�>��=⬒��˧L[�� �߿2JaB~R��u�:��Q�] �0H~���]�7��Ƽ�I���(}��cq '�ήET���q�?f�ab���ӥvr� �)o��-Q��_'����ᴎo��K������;��V���o��%���~OK ����*��b�f:���-ťIR��`B�5!RB@���ï�� �u �̯e\�_U�_������� g�ES��3�������QT��a����x����U<~�c?�*�#]�MW,[8O�a�x��]�1bC|踤�P��lw5V%�)�{t�<��d��5���0i�XSU��m:��Z�┵�i�"��1�^B�-��P�hJ��&)O��*�D��c�W��vM��)����}���P��ܗ-q����\mmζZ-l@�}��a��E�6��F�@��&Sg@���ݚ�M����� ȹ 4����#p�\H����dYDo�H���"��\��..R�B�H�z_�/5˘����6��KhJR��P�mƶi�m���3�,#c�co��q�a)*Pt����R�m�k�7x�D�E�\Y�閣_X�<���~�)���c[[�BP����6�Yq���S��0����%_����;��Àv�~�| VS؇ ��'O0��F0��\���U�-�d@�����7�SJ*z��3n��y��P����O���������m�~�P�3|Y��ʉr#�C�<�G~�.,! ���bqx���h~0=��!ǫ�jy����l�O,�[B��~��|9��ٱ����Xly�#�i�B��g%�S��������tˋ���e���ې��\[d�t)��.+u�|1 ������#�~Oj����hS�%��i.�~X���I�H�m��0n���c�1uE�q��cF�RF�o���7� �O�ꮧ� ���ۛ{��ʛi5�rw?׌#Qn�TW��~?y$��m\�\o����%W� ?=>S�N@�� �Ʈ���R����N�)�r"C�:��:����� �����#��qb��Y�. �6[��2K����2u�Ǧ�HYR��Q�MV��� �G�$��Q+.>�����nNH��q�^��� ����q��mM��V��D�+�-�#*�U�̒ ���p욳��u:�������IB���m���PV@O���r[b= �� ��1U�E��_Nm�yKbN�O���U�}�the�`�|6֮P>�\2�P�V���I�D�i�P�O;�9�r�mAHG�W�S]��J*�_�G��+kP�2����Ka�Z���H�'K�x�W�MZ%�O�YD�Rc+o��?�q��Ghm��d�S�oh�\�D�|:W������UA�Qc yT�q������~^�H��/��#p�CZ���T�I�1�ӏT����4��"�ČZ�����}��`w�#�*,ʹ�� ��0�i��課�Om�*�da��^gJ݅{���l�e9uF#T�ֲ��̲�ٞC"�q���ߍ ոޑ�o#�XZTp����@ o�8��(jd��xw�]�,f���`~�|,s��^����f�1���t��|��m�򸄭/ctr��5s��7�9Q�4�H1꠲BB@l9@���C�����+�wp�xu�£Yc�9��?`@#�o�mH�s2��)�=��2�.�l����jg�9$�Y�S�%*L������R�Y������7Z���,*=�䷘$�������arm�o�ϰ���UW.|�r�uf����IGw�t����Zwo��~5 ��YյhO+=8fF�)�W�7�L9lM�̘·Y���֘YLf�큹�pRF���99.A �"wz��=E\Z���'a� 2��Ǚ�#;�'}�G���*��l��^"q��+2FQ� hj��kŦ��${���ޮ-�T�٭cf�|�3#~�RJ����t��$b�(R��(����r���dx� >U b�&9,>���%E\� Ά�e�$��'�q't��*�א���ެ�b��-|d���SB�O�O��$�R+�H�)�܎�K��1m`;�J�2�Y~9��O�g8=vqD`K[�F)k�[���1m޼c��n���]s�k�z$@��)!I �x՝"v��9=�ZA=`Ɠi �:�E��)`7��vI��}d�YI�_ �o�:ob���o ���3Q��&D&�2=�� �Ά��;>�h����y.*ⅥS������Ӭ�+q&����j|UƧ����}���J0��WW< ۋS�)jQR�j���Ư��rN)�Gű�4Ѷ(�S)Ǣ�8��i��W52���No˓� ۍ%�5brOn�L�;�n��\G����=�^U�dI���8$�&���h��'���+�(������cȁ߫k�l��S^���cƗjԌE�ꭔ��gF���Ȓ��@���}O���*;e�v�WV���YJ\�]X'5��ղ�k�F��b 6R�o՜m��i N�i����>J����?��lPm�U��}>_Z&�KK��q�r��I�D�Չ~�q�3fL�:S�e>���E���-G���{L�6p�e,8��������QI��h��a�Xa��U�A'���ʂ���s�+טIjP�-��y�8ۈZ?J$��W�P� ��R�s�]��|�l(�ԓ��sƊi��o(��S0��Y� 8�T97.�����WiL��c�~�dxc�E|�2!�X�K�Ƙਫ਼�$((�6�~|d9u+�qd�^3�89��Y�6L�.I�����?���iI�q���9�)O/뚅����O���X��X�V��ZF[�یgQ�L��K1���RҖr@v�#��X�l��F���Нy�S�8�7�kF!A��sM���^rkp�jP�DyS$N���q��nxҍ!U�f�!eh�i�2�m���`�Y�I�9r�6� �TF���C}/�y�^���Η���5d�'��9A-��J��>{�_l+�`��A���[�'��յ�ϛ#w:݅�%��X�}�&�PSt�Q�"�-��\縵�/����$Ɨh�Xb�*�y��BS����;W�ջ_mc�����vt?2}1�;qS�d�d~u:2k5�2�R�~�z+|HE!)�Ǟl��7`��0�<�,�2*���Hl-��x�^����'_TV�gZA�'j� ^�2Ϊ��N7t�����?w�� �x1��f��Iz�C-Ȗ��K�^q�;���-W�DvT�7��8�Z�������� hK�(P:��Q- �8�n�Z���܃e貾�<�1�YT<�,�����"�6{/ �?�͟��|1�:�#g��W�>$����d��J��d�B��=��jf[��%rE^��il:��B���x���Sּ�1հ��,�=��*�7 fcG��#q� �eh?��2�7�����,�!7x��6�n�LC�4x��},Geǝ�tC.��vS �F�43��zz\��;QYC,6����~;RYS/6���|2���5���v��T��i����������mlv��������&� �nRh^ejR�LG�f���? �ۉҬܦƩ��|��Ȱ����>3����!v��i�ʯ�>�v��オ�X3e���_1z�Kȗ\<������!�8���V��]��?b�k41�Re��T�q��mz��TiOʦ�Z��Xq���L������q"+���2ۨ��8}�&N7XU7Ap�d�X��~�׿��&4e�o�F��� �H����O���č�c�� 懴�6���͉��+)��v;j��ݷ�� �UV�� i��� j���Y9GdÒJ1��詞�����V?h��l����l�cGs�ځ�������y�Ac�����\V3�? �� ܙg�>qH�S,�E�W�[�㺨�uch�⍸�O�}���a��>�q�6�n6����N6�q������N ! 1AQaq�0@����"2BRb�#Pr���3C`��Scst���$4D���%Td�� ?���N����a��3��m���C���w��������xA�m�q�m���m������$����4n淿t'��C"w��zU=D�\R+w�p+Y�T�&�պ@��ƃ��3ޯ?�Aﶂ��aŘ���@-�����Q�=���9D��ռ�ѻ@��M�V��P��܅�G5�f�Y<�u=,EC)�<�Fy'�"�&�չ�X~f��l�KԆV��?�� �W�N����=(� �;���{�r����ٌ�Y���h{�١������jW����P���Tc�����X�K�r��}���w�R��%��?���E��m�� �Y�q|����\lEE4���r���}�lsI�Y������f�$�=�d�yO����p�����yBj8jU�o�/�S��?�U��*������ˍ�0������u�q�m [�?f����a�� )Q�>����6#������� ?����0UQ����,IX���(6ڵ[�DI�MNލ�c&���υ�j\��X�R|,4��� j������T�hA�e��^���d���b<����n�� �즇�=!���3�^�`j�h�ȓr��jẕ�c�,ٞX����-����a�ﶔ���#�$��]w�O��Ӫ�1y%��L�Y<�wg#�ǝ�̗`�x�xa�t�w��»1���o7o5��>�m뭛C���Uƃߜ}�C���y1Xνm�F8�jI���]����H���ۺиE@I�i;r�8ӭ����V�F�Շ| ��&?�3|x�B�MuS�Ge�=Ӕ�#BE5G�����Y!z��_e��q�р/W>|-�Ci߇�t�1ޯќd�R3�u��g�=0 5��[?�#͏��q�cf���H��{ ?u�=?�?ǯ���}Z��z���hmΔ�BFTW�����<�q�(v� ��!��z���iW]*�J�V�z��gX֧A�q�&��/w���u�gYӘa���; �i=����g:��?2�dž6�ى�k�4�>�Pxs����}������G�9��3 ���)gG�R<>r h�$��'nc�h�P��Bj��J�ҧH� -��N1���N��?��~��}-q!=��_2hc�M��l�vY%UE�@|�v����M2�.Y[|y�"Eï��K�ZF,�ɯ?,q�?v�M 80jx�"�;�9vk�����+ ֧�� �ȺU��?�%�vcV��mA�6��Qg^M����A}�3�nl� QRN�l8�kkn�'�����(��M�7m9و�q���%ޟ���*h$Zk"��$�9��: �?U8�Sl��,,|ɒ��xH(ѷ����Gn�/Q�4�P��G�%��Ա8�N��!� �&�7�;���eKM7�4��9R/%����l�c>�x;������>��C�:�����t��h?aKX�bhe�ᜋ^�$�Iհ �hr7%F$�E��Fd���t��5���+�(M6�t����Ü�UU|zW�=a�Ts�Tg������dqP�Q����b'�m���1{|Y����X�N��b �P~��F^F:����k6�"�j!�� �I�r�`��1&�-$�Bevk:y���#yw��I0��x��=D�4��tU���P�ZH��ڠ底taP��6����b>�xa����Q�#� WeF��ŮNj�p�J* mQ�N����*I�-*�ȩ�F�g�3 �5��V�ʊ�ɮ�a��5F���O@{���NX��?����H�]3��1�Ri_u��������ѕ�� ����0��� F��~��:60�p�͈�S��qX#a�5>���`�o&+�<2�D����: �������ڝ�$�nP���*)�N�|y�Ej�F�5ټ�e���ihy�Z �>���k�bH�a�v��h�-#���!�Po=@k̆IEN��@��}Ll?j�O������߭�ʞ���Q|A07x���wt!xf���I2?Z��<ץ�T���cU�j��]��陎Ltl �}5�ϓ��$�,��O�mˊ�;�@O��jE��j(�ا,��LX���LO���Ц�90�O �.����a��nA���7������j4 ��W��_ٓ���zW�jcB������y՗+EM�)d���N�g6�y1_x��p�$Lv:��9�"z��p���ʙ$��^��JԼ*�ϭ����o���=x�Lj�6�J��u82�A�H�3$�ٕ@�=Vv�]�'�qEz�;I˼��)��=��ɯ���x �/�W(V���p�����$ �m�������u�����񶤑Oqˎ�T����r��㠚x�sr�GC��byp�G��1ߠ�w e�8�$⿄����/�M{*}��W�]˷.�CK\�ުx���/$�WPw���r� |i���&�}�{�X� �>��$-��l���?-z���g����lΆ���(F���h�vS*���b���߲ڡn,|)mrH[���a�3�ר�[1��3o_�U�3�TC�$��(�=�)0�kgP���� ��u�^=��4 �WYCҸ:��vQ�ר�X�à��tk�m,�t*��^�,�}D*� �"(�I��9R����>`�`��[~Q]�#af��i6l��8���6�:,s�s�N6�j"�A4���IuQ��6E,�GnH��zS�HO�uk�5$�I�4��ؤ�Q9�@��C����wp�BGv[]�u�Ov���0I4���\��y�����Q�Ѹ��~>Z��8�T��a��q�ޣ;z��a���/��S��I:�ܫ_�|������>=Z����8:�S��U�I�J��"IY���8%b8���H��:�QO�6�;7�I�S��J��ҌAά3��>c���E+&jf$eC+�z�;��V����� �r���ʺ������my�e���aQ�f&��6�ND��.:��NT�vm�<- u���ǝ\MvZY�N�NT��-A�>jr!S��n�O 1�3�Ns�%�3D@���`������ܟ 1�^c<���� �a�ɽ�̲�Xë#�w�|y�cW�=�9I*H8�p�^(4���՗�k��arOcW�tO�\�ƍR��8����'�K���I�Q�����?5�>[�}��yU�ײ -h��=��% q�ThG�2�)���"ו3]�!kB��*p�FDl�A���,�eEi�H�f�Ps�����5�H:�Փ~�H�0Dت�D�I����h�F3�������c��2���E��9�H��5�zԑ�ʚ�i�X�=:m�xg�hd(�v����׊�9iS��O��d@0ڽ���:�p�5�h-��t�&���X�q�ӕ,��ie�|���7A�2���O%P��E��htj��Y1��w�Ѓ!����  ���� ࢽ��My�7�\�a�@�ţ�J �4�Ȼ�F�@o�̒?4�wx��)��]�P��~�����u�����5�����7X ��9��^ܩ�U;Iꭆ 5 �������eK2�7(�{|��Y׎ �V��\"���Z�1� Z�����}��(�Ǝ"�1S���_�vE30>���p;� ΝD��%x�W�?W?v����o�^V�i�d��r[��/&>�~`�9Wh��y�;���R��� ;;ɮT��?����r$�g1�K����A��C��c��K��l:�'��3 c�ﳯ*"t8�~l��)���m��+U,z��`(�>yJ�?����h>��]��v��ЍG*�{`��;y]��I�T� ;c��NU�fo¾h���/$���|NS���1�S�"�H��V���T���4��uhǜ�]�v;���5�͠x��'C\�SBpl���h}�N����� A�Bx���%��ޭ�l��/����T��w�ʽ]D�=����K���ž�r㻠l4�S�O?=�k �M:� ��c�C�a�#ha���)�ѐxc�s���gP�iG��{+���x���Q���I= �� z��ԫ+ �8"�k�ñ�j=|����c ��y��CF��/��*9ж�h{ �?4�o� ��k�m�Q�N�x��;�Y��4膚�a�w?�6�>e]�����Q�r�:����g�,i"�����ԩA�*M�<�G��b�if��l^M��5� �Ҩ�{����6J��ZJ�����P�*�����Y���ݛu�_4�9�I8�7���������,^ToR���m4�H��?�N�S�ѕw��/S��甍�@�9H�S�T��t�ƻ���ʒU��*{Xs�@����f�����֒Li�K{H�w^���������Ϥm�tq���s� ���ք��f:��o~s��g�r��ט� �S�ѱC�e]�x���a��) ���(b-$(�j>�7q�B?ӕ�F��hV25r[7 Y� }L�R��}����*sg+��x�r�2�U=�*'WS��ZDW]�WǞ�<��叓���{�$�9Ou4��y�90-�1�'*D`�c�^o?(�9��u���ݐ��'PI&� f�Jݮ�������:wS����jfP1F:X �H�9dԯ���˝[�_54 �}*;@�ܨ�� ð�yn�T���?�ןd�#���4rG�ͨ��H�1�|-#���Mr�S3��G�3�����)�.᧏3v�z֑��r����$G"�`j �1t��x0<Ɔ�Wh6�y�6��,œ�Ga��gA����y��b��)��h�D��ß�_�m��ü �gG;��e�v��ݝ�nQ� ��C����-�*��o���y�a��M��I�>�<���]obD��"�:���G�A��-\%LT�8���c�)��+y76���o�Q�#*{�(F�⽕�y����=���rW�\p���۩�c���A���^e6��K������ʐ�cVf5$�'->���ՉN"���F�"�UQ@�f��Gb~��#�&�M=��8�ט�JNu9��D��[̤�s�o�~������ G��9T�tW^g5y$b��Y'��س�Ǵ�=��U-2 #�MC�t(�i� �lj�@Q 5�̣i�*�O����s�x�K�f��}\��M{E�V�{�υ��Ƈ�����);�H����I��fe�Lȣr�2��>��W�I�Ȃ6������i��k�� �5�YOxȺ����>��Y�f5'��|��H+��98pj�n�.O�y�������jY��~��i�w'������l�;�s�2��Y��:'lg�ꥴ)o#'Sa�a�K��Z� �m��}�`169�n���"���x��I ��*+� }F<��cГ���F�P�������ֹ*�PqX�x۩��,� ��N�� �4<-����%����:��7����W���u�`����� $�?�I��&����o��o��`v�>��P��"��l���4��5'�Z�gE���8���?��[�X�7(��.Q�-��*���ތL@̲����v��.5���[��=�t\+�CNܛ��,g�SQnH����}*F�G16���&:�t��4ُ"A��̣��$�b �|����#rs��a�����T�� ]�<�j��BS�('$�ɻ� �wP;�/�n��?�ݜ��x�F��yUn�~mL*-�������Xf�wd^�a�}��f�,=t�׵i�.2/wpN�Ep8�OР���•��R�FJ� 55TZ��T �ɭ�<��]��/�0�r�@�f��V��V����Nz�G��^���7hZi����k��3�,kN�e|�vg�1{9]_i��X5y7� 8e]�U����'�-2,���e"����]ot�I��Y_��n�(JҼ��1�O ]bXc���Nu�No��pS���Q_���_�?i�~�x h5d'�(qw52] ��'ޤ�q��o1�R!���`ywy�A4u���h<קy���\[~�4�\ X�Wt/� 6�����n�F�a8��f���z �3$�t(���q��q�x��^�XWeN'p<-v�!�{�(>ӽDP7��ո0�y)�e$ٕv�Ih'Q�EA�m*�H��RI��=:��� ���4牢) �%_iN�ݧ�l]� �Nt���G��H�L��� ɱ�g<���1V�,�J~�ٹ�"K��Q�� 9�HS�9�?@��k����r�;we݁�]I�!{ �@�G�[�"��`���J:�n]�{�cA�E����V��ʆ���#��U9�6����j�#Y�m\��q�e4h�B�7��C�������d<�?J����1g:ٳ���=Y���D�p�ц� ׈ǔ��1�]26؜oS�'��9�V�FVu�P�h�9�xc�oq�X��p�o�5��Ա5$�9W�V(�[Ak�aY錎qf;�'�[�|���b�6�Ck��)��#a#a˙��8���=äh�4��2��C��4tm^ �n'c���]GQ$[Wҿ��i���vN�{Fu ��1�gx��1┷���N�m��{j-,��x�� Ūm�ЧS�[�s���Gna���䑴�� x�p 8<������97�Q���ϴ�v�aϚG��Rt�Һ׈�f^\r��WH�JU�7Z���y)�vg=����n��4�_)y��D'y�6�]�c�5̪�\� �PF�k����&�c;��cq�$~T�7j ���nç]�<�g ":�to�t}�159�<�/�8������m�b�K#g'I'.W�����6��I/��>v��\�MN��g���m�A�yQL�4u�Lj�j9��#44�t��l^�}L����n��R��!��t��±]��r��h6ٍ>�yҏ�N��fU�� ���� Fm@�8}�/u��jb9������he:A�y�ծw��GpΧh�5����l}�3p468��)U��d��c����;Us/�֔�YX�1�O2��uq�s��`hwg�r~�{ R��mhN��؎*q 42�*th��>�#���E����#��Hv�O����q�}�����6�e��\�,Wk�#���X��b>��p}�դ��3���T5��†��6��[��@�P�y*n��|'f�֧>�lư΂�̺����SU�'*�q�p�_S�����M�� '��c�6�����m�� ySʨ;M��r���Ƌ�m�Kxo,���Gm�P��A�G�:��i��w�9�}M(�^�V��$ǒ�ѽ�9���|���� �a����J�SQ�a���r�B;����}���ٻ֢�2�%U���c�#�g���N�a�ݕ�'�v�[�OY'��3L�3�;,p�]@�S��{ls��X�'���c�jw�k'a�.��}�}&�� �dP�*�bK=ɍ!����;3n�gΊU�ߴmt�'*{,=SzfD� A��ko~�G�aoq�_mi}#�m�������P�Xhύ����mxǍ�΂���巿zf��Q���c���|kc�����?���W��Y�$���_Lv����l߶��c���`?����l�j�ݲˏ!V��6����U�Ђ(A���4y)H���p�Z_�x��>���e��R��$�/�`^'3qˏ�-&Q�=?��CFVR �D�fV�9��{�8g�������n�h�(P"��6�[�D���< E�����~0<@�`�G�6����Hг�cc�� �c�K.5��D��d�B���`?�XQ��2��ٿyqo&+�1^� DW�0�ꊩ���G�#��Q�nL3��c���������/��x ��1�1[y�x�პCW��C�c�UĨ80�m�e�4.{�m��u���I=��f�����0QRls9���f���������9���~f�����Ǩ��a�"@�8���ȁ�Q����#c�ic������G��$���G���r/$W�(��W���V�"��m�7�[m�A�m����bo��D� j����۳� l���^�k�h׽����� ��#� iXn�v��eT�k�a�^Y�4�BN��ĕ��0 !01@Q"2AaPq3BR������?���@4�Q�����T3,���㺠�W�[=JK�Ϟ���2�r^7��vc�:�9 �E�ߴ�w�S#d���Ix��u��:��Hp��9E!�� V 2;73|F��9Y���*ʬ�F��D����u&���y؟��^EA��A��(ɩ���^��GV:ݜDy�`��Jr29ܾ�㝉��[���E;Fzx��YG��U�e�Y�C���� ����v-tx����I�sם�Ę�q��Eb�+P\ :>�i�C'�;�����k|z�رn�y]�#ǿb��Q��������w�����(�r|ӹs��[�D��2v-%��@;�8<a���[\o[ϧw��I!��*0�krs)�[�J9^��ʜ��p1)� "��/_>��o��<1����A�E�y^�C��`�x1'ܣn�p��s`l���fQ��):�l����b>�Me�jH^?�kl3(�z:���1ŠK&?Q�~�{�ٺ�h�y���/�[��V�|6��}�KbX����mn[-��7�5q�94�������dm���c^���h� X��5��<�eޘ>G���-�}�دB�ޟ� ��|�rt�M��V+�]�c?�-#ڛ��^ǂ}���Lkr���O��u�>�-D�ry� D?:ޞ�U��ǜ�7�V��?瓮�"�#���r��չģVR;�n���/_� ؉v�ݶe5d�b9��/O��009�G���5n�W����JpA�*�r9�>�1��.[t���s�F���nQ� V 77R�]�ɫ8����_0<՜�IF�u(v��4��F�k�3��E)��N:��yڮe��P�`�1}�$WS��J�SQ�N�j�ٺ��޵�#l���ј(�5=��5�lǏmoW�v-�1����v,W�mn��߀$x�<����v�j(����c]��@#��1������Ǔ���o'��u+����;G�#�޸��v-lη��/(`i⣍Pm^���ԯ̾9Z��F��������n��1��� ��]�[��)�'������:�֪�W��FC����� �B9،!?���]��V��A�Վ�M��b�w��G F>_DȬ0¤�#�QR�[V��kz���m�w�"��9ZG�7'[��=�Q����j8R?�zf�\a�=��O�U����*oB�A�|G���2�54 �p��.w7� �� ��&������ξxGHp� B%��$g�����t�Џ򤵍z���HN�u�Я�-�'4��0��;_��3 !01"@AQa2Pq#3BR������?��ʩca��en��^��8���<�u#��m*08r��y�N"�<�Ѳ0��@\�p��� �����Kv�D��J8�Fҽ� �f�Y��-m�ybX�NP����}�!*8t(�OqѢ��Q�wW�K��ZD��Δ^e��!� ��B�K��p~�����e*l}z#9ң�k���q#�Ft�o��S�R����-�w�!�S���Ӥß|M�l޶V��!eˈ�8Y���c�ЮM2��tk���� ������J�fS����Ö*i/2�����n]�k�\���|4yX�8��U�P.���Ы[���l��@"�t�<������5�lF���vU�����W��W��;�b�cД^6[#7@vU�xgZv��F�6��Q,K�v��� �+Ъ��n��Ǣ��Ft���8��0��c�@�!�Zq s�v�t�;#](B��-�nῃ~���3g������5�J�%���O������n�kB�ĺ�.r��+���#�N$?�q�/�s�6��p��a����a��J/��M�8��6�ܰ"�*������ɗud"\w���aT(����[��F��U՛����RT�b���n�*��6���O��SJ�.�ij<�v�MT��R\c��5l�sZB>F��<7�;EA��{��E���Ö��1U/�#��d1�a�n.1ě����0�ʾR�h��|�R��Ao�3�m3 ��%�� ���28Q� ��y��φ���H�To�7�lW>����#i`�q���c����a��� �m,B�-j����݋�'mR1Ήt�>��V��p���s�0IbI�C.���1R�ea�����]H�6����������4B>��o��](��$B���m�����a�!=��?�B� K�Ǿ+�Ծ"�n���K��*��+��[T#�{E�J�S����Q�����s�5�:�U�\wĐ�f�3����܆&�)����I���Ԇw��E T�lrTf6Q|R�h:��[K�� �z��c֧�G�C��%\��_�a�84��HcO�bi��ؖV��7H �)*ģK~Xhչ0��4?�0��� �E<���}3���#���u�?�� ��|g�S�6ꊤ�|�I#Hڛ� �ա��w�X��9��7���Ŀ%�SL��y6č��|�F�a 8���b��$�sק�h���b9RAu7�˨p�Č�_\*w��묦��F ����4D~�f����|(�"m���NK��i�S�>�$d7SlA��/�²����SL��|6N�}���S�˯���g��]6��; �#�.��<���q'Q�1|KQ$�����񛩶"�$r�b:���N8�w@��8$�� �AjfG|~�9F ���Y��ʺ��Bwؒ������M:I岎�G��`s�YV5����6��A �b:�W���G�q%l�����F��H���7�������Fsv7��k�� 403WebShell
403Webshell
Server IP : 51.161.54.47  /  Your IP : 216.73.216.114
Web Server : Apache/2.4.68 (Unix) OpenSSL/1.1.1k
System : Linux host.ditinformatica.ar 4.18.0-553.144.1.el8_10.x86_64 #1 SMP Tue Jul 14 09:26:58 EDT 2026 x86_64
User : kalaycom ( 1021)
PHP Version : 7.4.33
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /usr/share/nmap/nselib/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /usr/share/nmap/nselib/rmi.lua
--- Library method for communicating over RMI (JRMP + java serialization)
--
-- This is a not complete RMI implementation for Lua, which is meant to be able
-- to invoke methods and parse returnvalues which are simple, basically the java primitives.
-- This can be used to e.g dump out the registry, and perform authentication against
-- e.g JMX-services.
--
-- This library also contains some classes which works pretty much like the
-- java classes BufferedReader, BufferedWriter, DataOutputStream and DataInputStream.
--
-- Most of the methods in the RMIDataStream class is based on the OpenJDK RMI Implementation,
-- and I have kept the methodnames  as they are in java, so it should not be too hard to find
-- the corresponding functionality in the jdk codebase to see how things 'should' be done, in case
-- there are bugs or someone wants to make additions. I have only implemented the
-- things that were needed to get things working, but it should be pretty simple to add more
-- functionality by lifting over more stuff from the jdk.
--
-- The interesting classes in OpenJDK are:
--  java.io.ObjectStreamConstants
--  java.io.ObjectStreamClass
--  java.io.ObjectInputStream
--  sun.rmi.transport.StreamRemoteCall
-- and a few more.
--
-- If you want to add calls to classes you know of, you can use e.g Jode to decompile the
-- stub-class or skeleton class and find out the details that are needed to perform an
-- RMI method invocation. Those are
--  Class hashcode
--  Method number (each method gets a number)
--  Arguments f
-- You also need the object id (so the remote server knows what instance you are talking to). That can be
-- fetched from the registry (afaik) but not currently implemented. Some object ids are static : the registry is always 0
--
-- @author Martin Holst Swende
-- @copyright Same as Nmap--See https://nmap.org/book/man-legal.html
-- @see java 1.4 RMI-spec: http://java.sun.com/j2se/1.4.2/docs/guide/rmi/
-- @see java 5 RMI-spec: http://java.sun.com/j2se/1.5.0/docs/guide/rmi/spec/rmiTOC.html
-- @see java 6 RMI-spec : http://java.sun.com/javase/6/docs/technotes/guides/rmi/index.html
-- @see The protocol for Java object serializtion : http://java.sun.com/javase/6/docs/platform/serialization/spec/protocol.html
-- Version 0.2

-- Created 09/06/2010 - v0.1 - created by Martin Holst Swende <martin@swende.se>
-- Fixed more documentation - v0.2 Martin Holst Swende <martin@swende.se>

local nmap = require "nmap"
local stdnse = require "stdnse"
local string = require "string"
local table = require "table"
_ENV = stdnse.module("rmi", stdnse.seeall)
-- Some lazy shortcuts

local function dbg(str,...)
  local arg={...}
  stdnse.debug3("RMI:"..str, table.unpack(arg))
end
-- Convenience function to both print an error message and return <false, msg>
-- Example usage :
-- if foo ~= "gazonk" then
--   return doh("Foo should be gazonk but was %s", foo)
-- end
local function doh(str,...)
  local arg={...}
  stdnse.debug1("RMI-ERR:"..tostring(str), table.unpack(arg))
  return false, str
end

---
-- BufferedWriter
-- This buffering writer provide functionality much like javas BufferedWriter.
--
-- BufferedWriter wraps string.pack, and buffers data internally
-- until flush is called. When flush is called, it either sends the data to the socket OR
-- returns the data, if no socket has been set.
--@usage:
-- local bWriter = BufferedWriter:new(socket)
-- local breader= BufferedReader:new(socket)
--
-- bWriter.pack('>i4', integer)
-- bWriter.flush() -- sends the data
--
-- if bsocket:canRead(4) then -- Waits until four bytes can be read
--   local packetLength = bsocket:unpack('>i4') -- Read the four bytess
--   if bsocket:canRead(packetLength) then
--     -- ...continue reading packet values

BufferedWriter = {
  new = function(self, socket)
    local o = {}
    setmetatable(o, self)
    self.__index = self
    o.writeBuffer = ''
    o.pos = 1
    o.socket = socket
    return o
  end,

  -- Sends data over the socket
  -- (Actually, just buffers until flushed)
  -- @return Status (true or false).
  -- @return Error code (if status is false).
  send = function( self, data )
    self.writeBuffer = self.writeBuffer .. data
  end,
  -- Convenience function, wraps string.pack
  pack = function(self, fmt, ... )
    local arg={...}
    self.writeBuffer = self.writeBuffer .. string.pack( fmt, table.unpack(arg))
  end,

  -- This function flushes the buffer contents, thereby emptying
  -- the buffer. If a socket has been supplied, that's where it will be sent
  -- otherwise the buffer contents are returned
  --@return status
  --@return content of buffer, in case no socket was used
  flush = function(self)

    local content = self.writeBuffer
    self.writeBuffer = ''

    if not self.socket then
      return true, content
    end
    return self.socket:send(content)
  end,

}
---
-- BufferedReader reads data from the supplied socket and contains functionality
-- to read all that is available and store all that is not currently needed, so the caller
-- gets an exact number of bytes (which is not the case with the basic nmap socket implementation)
-- If not enough data is available, it blocks until data is received, thereby handling the case
-- if data is spread over several tcp packets (which is a pitfall for many scripts)
--
-- It wraps string.unpack for the reading.
-- OBS! You need to check before invoking skip or unpack that there is enough
-- data to read. Since this class does not parse arguments to unpack, it does not
-- know how much data to read ahead on those calls.
--@usage:
-- local bWriter = BufferedWriter:new(socket)
-- local breader= BufferedReader:new(socket)
--
-- bWriter.pack('>i4', integer)
-- bWriter.flush() -- sends the data
--
-- if bsocket:canRead(4) then -- Waits until four bytes can be read
--   local packetLength = bsocket:unpack('>i4') -- Read the four bytess
--   if bsocket:canRead(packetLength) then
--     -- ...continue reading packet values

BufferedReader = {
  new = function(self, socket, readBuffer)
    local o = {}
    setmetatable(o, self)
    self.__index = self
    o.readBuffer = readBuffer -- May be nil
    o.pos = 1
    o.socket = socket -- May also be nil
    return o
  end,
  ---
  -- This method blocks until the specified number of bytes
  -- have been read from the socket and are available for
  -- the caller to read, e.g via the unpack function
  canRead= function(self,count)
    local status, data
    self.readBuffer = self.readBuffer or ""
    local missing = self.pos + count - #self.readBuffer -1
    if ( missing > 0) then
      if self.socket == nil then
        return doh("Not enough data in static buffer")
      end

      status, data = self.socket:receive_bytes( missing )
      if ( not(status) ) then
        return false, data
      end
      self.readBuffer = self.readBuffer .. data
    end
    -- Now and then, we flush the buffer
    if ( self.pos > 1024) then
      self.readBuffer = self.readBuffer:sub( self.pos )
      self.pos = 1
    end
    return true
  end,
  ---
  --@return Returns the number of bytes already available for reading
  bufferSize = function(self)
    return #self.readBuffer +1 -self.pos
  end,
  ---
  -- This function works just like string.unpack (in fact, it is
  -- merely a wrapper around it.  However, it uses the data
  -- already read into the buffer, and the internal position
  --@param format
  --@return the unpacked value (NOT the index)
  unpack = function(self,format)
    local ret = {string.unpack(format, self.readBuffer, self.pos)}
    self.pos = ret[#ret]
    ret[#ret] = nil
    return table.unpack(ret)
  end,
  ---
  -- This function works just like string.unpack (in fact, it is
  -- merely a wrapper around it.  However, it uses the data
  -- already read into the buffer, and the internal position.
  -- This method does not update the current position, and the
  -- data can be read again
  --@param format
  --@return the unpacked value (NOT the index)
  peekUnpack = function(self,format)
    return string.unpack(format, self.readBuffer, self.pos)
  end,
  ---
  -- Tries to read a byte, without consuming it.
  --@return status
  --@return bytevalue
  peekByte = function(self)
    if self:canRead(1) then
      return true, self:peekUnpack('B')
    end
    return false
  end,
  ---
  -- Skips a number of bytes
  --@param len the number of bytes to skip
  skip = function(self, len)
    if(#self.readBuffer < len + self.pos) then
      return doh("ERROR: reading too far ahead")
    end
    local skipped = self.readBuffer:sub(self.pos, self.pos+len-1)
    self.pos = self.pos + len
    return true, skipped
  end,

}

-- The classes are generated when this file is loaded, by the definitions in the JavaTypes
-- table. That table contains mappings between the format used by string.pack and the types
-- available in java, as well as the lengths (used for availability-checks) and the name which
-- is prefixed by read* or write* when monkey-patching the classes and adding functions.
-- For example: {name = 'Int', expr = '>i', len=  4}, will generate the functions
-- writeInt(self, value) and readInt() respectively

local JavaTypes = {
  {name = 'Int', expr = '>i4', len=  4},
  {name = 'UnsignedInt', expr = '>I4', len=  4},
  {name = 'Short', expr = '>i2', len=  2},
  {name = 'UnsignedShort', expr = '>I2', len=  2},
  {name = 'Long', expr = '>i8', len=  8},
  {name = 'UnsignedLong', expr = '>I8', len=  8},
  {name = 'Byte', expr = '>B', len=  1},
}

---
-- The JavaDOS classes
-- The JavaDOS class is an approximation of a java DataOutputStream. It provides convenience functions
-- for writing java types to an underlying BufferedWriter
--
-- When used in conjunction with the BufferedX- classes, they handle the availability-
-- checks transparently, i.e the caller does not have to check if enough data is available
--
-- @usage:
-- local dos = JavaDOS:new(BufferedWriter:new(socket))
-- local dos = JavaDIS:new(BufferedReader:new(socket))
-- dos:writeUTF("Hello world")
-- dos:writeInt(3)
-- dos:writeLong(3)
-- dos:flush() -- send data
-- local answer = dis:readUTF()
-- local int = dis:readInt()
-- local long = dis:readLong()

JavaDOS = {
  new = function  (self,bWriter)
    local o = {}   -- create new object if user does not provide one
    setmetatable(o, self)
    self.__index = self -- DIY inheritance
    o.bWriter = bWriter
    return o
  end,
  -- This closure method generates all writer methods on the fly
  -- according to the definitions in JavaTypes
  _generateWriterFunc = function(self, javatype)
    local functionName = 'write'..javatype.name
    local newFunc = function(_self, value)
      --dbg(functionName .."(%s) called" ,tostring(value))
      return _self:pack(javatype.expr, value)
    end
    self[functionName] = newFunc
  end,

  writeUTF = function(self, text)
    -- TODO: Make utf-8 of it
    return self:pack('>s2', text)
  end,
  pack = function(self, ...)
    local arg={...}
    return self.bWriter:pack(table.unpack(arg))
  end,
  write = function(self, data)
    return self.bWriter:send(data)
  end,
  flush = function(self)
    return self.bWriter:flush()
  end,
}

---
-- The JavaDIS class
-- JavaDIS is close to java DataInputStream. It provides convenience functions
-- for reading java types from an underlying BufferedReader
--
-- When used in conjunction with the BufferedX- classes, they handle the availability-
-- checks transparently, i.e the caller does not have to check if enough data is available
--
-- @usage:
-- local dos = JavaDOS:new(BufferedWriter:new(socket))
-- local dos = JavaDIS:new(BufferedReader:new(socket))
-- dos:writeUTF("Hello world")
-- dos:writeInt(3)
-- dos:writeLong(3)
-- dos:flush() -- send data
-- local answer = dis:readUTF()
-- local int = dis:readInt()
-- local long = dis:readLong()
JavaDIS = {
  new = function  (self,bReader)
    local o = {}   -- create new object if user does not provide one
    setmetatable(o, self)
    self.__index = self -- DIY inheritance
    o.bReader = bReader
    return o
  end,

  -- This closure method generates all reader methods (except nonstandard ones) on the fly
  -- according to the definitions in JavaTypes.
  _generateReaderFunc = function(self, javatype)
    local functionName = 'read'..javatype.name
    local newFunc = function(_self)
      --dbg(functionName .."() called" )
      if not _self.bReader:canRead(javatype.len)  then
        local err = ("Not enough data in buffer (%d required by %s)"):format(javatype.len, functionName)
        return doh(err)
      end
      return true, _self.bReader:unpack(javatype.expr)
    end
    self[functionName] = newFunc
  end,
  -- This is a bit special, since we do not know beforehand how many bytes must be read. Therefore
  -- this cannot be generated on the fly like the others.
  readUTF = function(self, text)
    -- First, we need to read the length, 2 bytes
    if not self.bReader:canRead(2)  then-- Length of the string is two bytes
      return false, "Not enough data in buffer [0]"
    end
    -- We do it as a 'peek', so string.unpack can reuse the data to unpack with '>s2'
    local len = self.bReader:peekUnpack('>I2')
    --dbg("Reading utf, len %d" , len)
    -- Check that we have data
    if not self.bReader:canRead(len) then
      return false, "Not enough data in buffer [1]"
    end
    -- For some reason, the 'P' switch does not work for me.
    -- Probably some idiot thing. This is a hack:
    local val = self.bReader.readBuffer:sub(self.bReader.pos+2, self.bReader.pos+len+2-1)
    self.bReader.pos = self.bReader.pos+len+2
    -- Someone smarter than me can maybe get this working instead:
    --local val = self.bReader:unpack('>s2')
    --dbg("Read UTF: %s", val)
    return true, val
  end,
  readLongAsHexString = function(self)
    if not self.bReader:canRead(8)  then-- Length of the string is two bytes
      return false, "Not enough data in buffer [3]"
    end
    return true, stdnse.tohex(self.bReader:unpack('c8'))

  end,
  skip = function(self, len)
    return self.bReader:skip(len)
  end,
  canRead = function(self, len)
    return self.bReader:canRead(len)
  end,
}

-- Generate writer-functions on the JavaDOS/JavaDIS classes on the fly
for _,x in ipairs(JavaTypes) do
  JavaDOS._generateWriterFunc(JavaDOS, x)
  JavaDIS._generateReaderFunc(JavaDIS, x)
end
---
-- This class represents a java class and is what is returned by the library
-- when invoking a remote function. Therefore, this can also represent a java
-- object instance.
JavaClass = {
  new = function(self)
    local o = {}
    setmetatable(o, self)
    self.__index = self
    return o
  end,

  customDataFormatter  = nil,

  setName = function( self, name )
    dbg("Setting class name to %s", name)
    self.name = name
  end,
  setSerialID = function( self, serial ) self.serial = serial end,
  setFlags = function( self, flags )
    self.flags = RMIUtils.flagsToString(flags)
    self._binaryflags = flags
  end,

  isExternalizable = function(self)
    if self._binaryFlags == nil then return false end

    return (self._binaryflags & RMIUtils.SC_EXTERNALIZABLE)
  end,

  addField = function( self, field )
    if self.fields == nil then self.fields = {} end
    table.insert( self.fields, field )
    --self[field.name] = field
  end,
  setSuperClass = function(self,super) self.superClass = super end,

  setCustomData = function(self, data) self.customData = data end,
  getCustomData = function(self) return self.customData end,

  setInterfaces = function(self,ifaces) self.ifaces = ifaces end,
  getName = function( self ) return self.name end,
  getSuperClass = function(self) return self.superClass end,
  getSerialID = function( self ) return self.serial end,
  getFlags = function( self ) return self.flags end,
  getFields = function( self ) return self.fields end,
  getFieldByName = function( self, name )
    if self.fields == nil then return end
    for i=1, #self.fields do
      if ( self.fields[i].name == name ) then
        return self.fields[i]
      end
    end
  end,

  __tostring = function( self )
    local data = {}
    if self.name ~=nil then
      data[#data+1] = ("%s "):format(self.name)
    else
      data[#data+1] = "???"
    end
    if  self.superClass~=nil then
      data[#data+1] = " extends ".. tostring( self.superClass)
    end
    if self.ifaces ~= nil then
      data[#data+1] = " implements " ..  self.ifaces
    end
    if self.fields ~=nil then
      for i=1, #self.fields do
        if i == 1 then
          data[#data+1] = "["
        end
        data[#data+1] = tostring(self.fields[i])
        if ( i < #self.fields ) then
          data[#data+1] = ";"
        else
          data[#data+1] = "]"
        end

      end
    end
    return table.concat(data)
  end,
  toTable = function(self, customDataFormatter)
    local data = {self.name}

    if self.externalData ~=nil then
      table.insert(data, tostring(self.externalData))
    end

    --if self.name ~=nil then
    --  data.class = self.name
    --end
    if self.ifaces ~= nil then
      table.insert(data, " implements " .. self.ifaces)
    end

    if  self.superClass~=nil then
      local extends = self.superClass:toTable()
      table.insert(data ,"extends")
      table.insert(data, extends)
      --data.extends = self.superClass:toTable()
    end
    if self.fields ~=nil then
      table.insert(data, "fields")
      local f = {}
      for i=1, #self.fields do
        table.insert(f, self.fields[i]:toTable())
      end
      table.insert(data, f)
    end

    if self.customData ~=nil then
      local formatter =  JavaClass['customDataFormatter']
      if formatter ~= nil then
        local title, cdata = formatter(self.name, self.customData)
        table.insert(data, title)
        table.insert(data, cdata)
      else
        table.insert(data, "Custom data")
        table.insert(data, self.customData)
      end
    end

    return data

  end,

}
--- Represents a field in an object, i.e an object member
JavaField = {

  new = function(self, name, typ )
    local o = {}
    setmetatable(o, self)
    self.__index = self
    o.name = name
    o.type = typ
    return o
  end,

  setType = function( self, typ ) self.type = typ end,
  setSignature = function( self, sig ) self.signature = sig end,
  setName = function( self, name ) self.name = name end,
  setObjectType = function( self, ot ) self.object_type = ot end,
  setReference = function( self, ref ) self.ref = ref end,
  setValue = function (self, val)
    dbg("Setting field value to %s", tostring(val))
    self.value = val

  end,

  getType = function( self ) return self.type end,
  getSignature = function( self ) return self.signature end,
  getName  = function( self ) return self.name end,
  getObjectType = function( self ) return self.object_type end,
  getReference = function( self ) return self.ref end,
  getValue = function( self ) return self.value end,

  __tostring = function( self )
    if self.value ~= nil then
      return string.format("%s %s = %s", self.type, self.name, self.value)
    else
      return string.format("%s %s", self.type, self.name)
    end
  end,
  toTable = function(self)
    local data = {tostring(self.type) .. " " .. tostring(self.name)}
    --print("FIELD VALUE:", self.value)
    if self.value ~= nil then
      if type(self.value) == 'table' then
        if self.value.toTable ~=nil then
          table.insert(data, self.value:toTable())
        else
          table.insert(data, self.value)
        end
      else
        table.insert(data, self.value)
      end
    end
    return data
  end,

}
---
-- Represents a java array. Internally, this is a lua list of JavaClass-instances
JavaArray = {
  new = function(self)
    local o = {}
    setmetatable(o, self)
    self.__index = self
    o.values = {}
    return o
  end,
  setClass = function( self, class ) self.class = class end,
  setLength = function( self, length ) self.length = length end,
  setValue = function(self, index, object) self.values[index] = object end,
  __tostring=function(self)
    local data = {
      ("Array: %s [%d] = {"):format(tostring(self.class), self.length)
    }

    for i=1, #self.values do
      data[#data+1] = self.values[i]..","
    end
    data[#data+1] = "}"
    return table.concat(data)
  end,
  toTable = function(self)
    local title = ("Array: %s [%d] = {"):format(tostring(self.class), self.length)
    local t =  {title = self.values}
    return t
  end,

  getValues = function(self) return self.values end
}





TC = {
  TC_NULL = 0x70,
  TC_REFERENCE = 0x71,
  TC_CLASSDESC = 0x72,
  TC_OBJECT = 0x73,
  TC_STRING = 0x74,
  TC_ARRAY = 0x75,
  TC_CLASS = 0x76,
  TC_BLOCKDATA = 0x77,
  TC_ENDBLOCKDATA = 0x78,
  TC_RESET = 0x79,
  TC_BLOCKDATALONG = 0x7A,
  TC_EXCEPTION = 0x7B,
  TC_LONGSTRING =  0x7C,
  TC_PROXYCLASSDESC =  0x7D,
  TC_ENUM =  0x7E,

  Integer = 0x49,
  Object = 0x4c,

  Strings = {
    [0x49] = "Integer",
    [0x4c] = "Object",
    [0x71] = "TC_REFERENCE",
    [0x70] = "TC_NULL",
    [0x71] = "TC_REFERENCE",
    [0x72] = "TC_CLASSDESC",
    [0x73] = "TC_OBJECT",
    [0x74] = "TC_STRING",
    [0x75] = "TC_ARRAY",
    [0x76] = "TC_CLASS",
    [0x77] = "TC_BLOCKDATA",
    [0x78] = "TC_ENDBLOCKDATA",
    [0x79] = "TC_RESET",
    [0x7A] = "TC_BLOCKDATALONG",
    [0x7B] = "TC_EXCEPTION",
    [0x7C] = "TC_LONGSTRING",
    [0x7D] = "TC_PROXYCLASSDESC",
    [0x7E] = "TC_ENUM",
  },

}

local Version= 0x02
local Proto= {Stream=0x4b, SingleOp=0x4c, Multiplex=0x4d}

---
-- RmiDataStream class
-- This class can handle reading and writing JRMP, i.e RMI wire protocol and
-- can do some very limited java deserialization. This implementation has
-- borrowed from OpenJDK RMI implementation, but only implements an
-- absolute minimum of what is required in order to perform some basic calls
--

RmiDataStream = {
  new = function  (self,o)
    o = o or {}   -- create object if user does not provide one
    setmetatable(o, self)
    self.__index = self -- DIY inheritance
    return o
  end,
}
-- An output stream in RMI consists of transport Header information followed by a sequence of Messages.
--  Out:
--    Header Messages
--    HttpMessage
--  Header:
--    0x4a 0x52 0x4d 0x49 Version Protocol
-- (4a 52 4d 49 === JRMI)
--  Version:
--    0x00 0x01
--  Protocol:
--    StreamProtocol
--    SingleOpProtocol
--    MultiplexProtocol
--  StreamProtocol:
--    0x4b
--  SingleOpProtocol:
--    0x4c
--  MultiplexProtocol:
--    0x4d
--  Messages:
--    Message
--    Messages Message

----
-- Connects to a remote service. The connection process creates a
-- socket and does some handshaking. If this is successful,
-- we are definitely talking to an RMI service.
function RmiDataStream:connect(host, port)
  local status, err

  local socket = nmap.new_socket()
  socket:set_timeout(5000)

  --  local bsocket = BufferedSocket:new()
  socket:connect(host,port, "tcp")

  -- Output and input
  local dos = JavaDOS:new(BufferedWriter:new(socket))
  local dis = JavaDIS:new(BufferedReader:new(socket))

  -- Start sending a message --
  -- Add Header, Version and Protocol

  dos:writeInt(1246907721) -- == JRMI
  dos:writeShort(Version)
  dos:writeByte(Proto.Stream)
  status = dos:flush()
  if not status then
    return doh(err)
  end

  -- For the StreamProtocol and the MultiplexProtocol, the server must respond with a a byte 0x4e
  -- acknowledging support for the protocol, and an EndpointIdentifier that contains the host name
  -- and port number that the server can see is being used by the client.
  -- The client can use this information to determine its host name if it is otherwise unable to do that for security reasons.

  -- Read ack
  status, err = self:readAck(dis)
  if not status then
    return doh("No ack received from server:" .. tostring(err))
  end

  -- The client must then respond with another EndpointIdentifier that contains the clients
  -- default endpoint for accepting connections. This can be used by a server in the MultiplexProtocol case to identify the client.

  dos:writeUTF("127.0.0.1") -- TODO, write our own ip instead (perhaps not necessary, since we are not using MultiplexProtocol
  dos:writeInt(0) -- Port ( 0 works fine)
  dos:flush()
  self.dos = dos
  self.dis =dis
  return true
end

-- Reads a DgcAck message, which is sent during connection handshake
--@param dis - a JavaDIS to read from
--@return status
--@return error message
function RmiDataStream:readAck(dis)
  local status, ack = dis:readByte()

  if not status then return doh( "Could not read data") end

  if ack ~= 78 then
    return doh("No ack received: ".. tostring(ack))
  end
  local status, host = dis:readUTF()
  if not status then return false, "Could not read data" end
  local status, port = dis:readUnsignedInt()
  if not status then return false, "Could not read data" end

  dbg("RMI-Ack received (host %s, port: %d) " , host, port)
  return true
end

-- Sends an RMI method call
--@param out - a JavaDos outputstream
--@param objNum -object id (target of call)
--@param hash - the hashcode for the class that is invoked
--@param op - the operation number (method) invoked
--@param arguments - optional, if arguments are needed to this method. Should be an Arguments table
--  or something else which has a getData() function to get binary data
function RmiDataStream:writeMethodCall(out,objNum, hash, op, arguments)
  dbg("Invoking object %s, hash %s, opNum %s, args %s", tostring(objNum), tostring(hash), tostring(op), tostring(arguments))
  local dos = self.dos
  local dis = self.dis

  -- Send Call:
  dos:writeByte(0x50)
  -- Send Magic 0xaced
  dos:writeUnsignedShort(0xACED)
  -- Send version 0x0005
  dos:writeShort(0x0005)
  -- Send TC_BLOKDATA
  dos:writeByte(0x77)

  -- send length (byte)
  dos:writeByte(0x22)

  -- From sun.rmi.transport.StreamRemoteCall :
  --   // write out remote call header info...
  --   // call header, part 1 (read by Transport)
  --   conn.getOutputStream().write(TransportConstants.Call);
  --   getOutputStream();           // creates a MarshalOutputStream
  --   id.write(out);               // object id (target of call)
  --   // call header, part 2 (read by Dispatcher)
  --   out.writeInt(op);            // method number (operation index)
  --   out.writeLong(hash);         // stub/skeleton hash
  -- Send rest of the call

  local unique, time, count =0,0,0

  dos:writeLong(objNum);-- id objNum
  dos:writeInt(unique); -- space
  dos:writeLong(time);
  dos:writeShort(count);
  dos:writeInt(op)
  dos:write(stdnse.fromhex(hash))

  -- And now, the arguments
  if arguments ~= nil then
    dos:write(arguments:getData())
  end


  dos:flush()

end
---
-- Invokes a method over RMI
--@param methodData, a table which should contain the following
--@param objNum -object id (target of call)
--@param hash - the hashcode for the class that is invoked
--@param op - the operation number (method) invoked
--@param arguments - optional, if arguments are needed to this method. Should be an Arguments table
--  or something else which has a getData() function to get binary data
--@return status
--@return a JavaClass instance
function RmiDataStream:invoke(objNum, hash, op, arguments)
  local status, data
  local out = self.out
  local dis = self.dis
  self:writeMethodCall(out,objNum,hash, op, arguments)
  local status, retByte = dis:readByte()
  if not status then return false, "No return data received from server" end

  if 0x51 ~= retByte then -- 0x51 : Returndata
    return false, "No return data received from server"
  end

  status, data = self:readReturnData(dis)
  return status, data
end

---
-- Reads an RMI ReturnData packet
--@param dis a JavaDIS inputstream
function RmiDataStream:readReturnData(dis)

  --[[
  From -http://turtle.ee.ncku.edu.tw/docs/java/jdk1.2.2/guide/rmi/spec/rmi-protocol.doc3.html :
  A ReturnValue of an RMI call consists of a return code to indicate either a normal or
  exceptional return, a UniqueIdentifier to tag the return value (used to send a DGCAck if necessary)
  followed by the return result: either the Value returned or the Exception thrown.


  CallData: ObjectIdentifier Operation Hash (Arguments)
  ReturnValue:
    0x01 UniqueIdentifier (Value)
    0x02 UniqueIdentifier Exception

  ObjectIdentifier: ObjectNumber UniqueIdentifier
  UniqueIdentifier: Number Time Count
  Arguments: Value Arguments Value
  Value: Object Primitive

  Example:  [ac ed][00 05][77][0f][01][25 14 95 21][00 00 01 2b 16 9a 62 5a 80 0b]
      [magc][ver    ][BL][L ][Ok][ --------------- not interesting atm ----------------------]

  --]]

  -- We need to be able to read at least 7 bytes
  -- If that is doable, we can ignore the status on the following readbyte operations
  if not dis:canRead(7) then
    return doh("Not enough data received")
  end

  local status, magic = dis:readUnsignedShort() -- read magic
  local status, version = dis:readShort() -- read version


  local status, typ = dis:readByte()
  if typ ~= TC.TC_BLOCKDATA then
    return doh("Expected block data when reading return data")
  end
  local status, len = dis:readByte() -- packet length
  --dis:setReadLimit(len)
  local status, ex = dis:readByte() -- 1=ok, 2=exception thrown
  if ex ~= 1 then
    return doh("Remote call threw exception")
  end

  -- We can skip the rest of this block
  dis:skip(len -1)

  -- Now, the return value object:
  local status, x = readObject0(dis)
  dbg("Read object, got %d left in buffer", dis.bReader:bufferSize())


  if(dis.bReader:bufferSize() > 0) then
    local content = dis.bReader:unpack('c'..tostring(dis.bReader:bufferSize()))
    dbg("Buffer content: %s", stdnse.tohex(content))
  end
  return status, x
end
---
-- Deserializes a serialized java object
function readObject0(dis)

  local finished = false
  local data, status, responseType

  status, responseType = dis:readByte()
  if not status then
    return doh("Not enough data received")
  end

  dbg("Reading object of type : %s" , RMIUtils.tcString(responseType))
  local decoder = TypeDecoders[responseType]
  if decoder ~= nil then
    status, data = decoder(dis)
    if not status then return doh("readObject0: Could not read data %s", tostring(data)) end
    dbg("Read: %s", tostring(data))
    return true, data
  else
    return doh("No decoder found for responsetype: %s" , RMIUtils.tcString(responseType))
  end
end
function readString(dis)
  return dis:readUTF()
end
-- Reads return type array
function readArray(dis)
  local array  = JavaArray:new()
  dbg("Reading array class description")
  local status, classDesc = readClassDesc(dis)
  array:setClass(classDesc)
  dbg("Reading array length")
  local status, len = dis:readInt()

  if not status then
    return doh("Could not read data")
  end

  array:setLength(len)
  dbg("Reading array of length is %X", len)
  for i =1, len, 1 do
    local status, object = readObject0(dis)
    array:setValue(i,object)
  end
  return true, array
end

function readClassDesc(dis)
  local status, p = dis:readByte()
  if not status then return doh( "Could not read data" ) end

  dbg("reading classdesc: %s" , RMIUtils.tcString(p))

  local val

  if p == TC.TC_CLASSDESC then
    dbg("Reading TC_CLASSDESC")
    status, val = readNonProxyDesc(dis)
  elseif p == TC.TC_NULL then
    dbg("Reading TC_NULL")
    status, val = true, nil
  elseif p == TC.TC_PROXYCLASSDESC then
    dbg("Reading TC_PROXYCLASSDESC")
    status, val = readProxyDesc(dis)
  else
    return doh("TC_classdesc is other %d", p)
  end

  if not status then
    return doh("Error reading class description")
  end
  return status, val


end
function readOrdinaryObject(dis)
  local status, desc =  readClassDesc(dis)
  if not status then
    return doh("Error reading ordinary object")
  end


  if  desc:isExternalizable() then
    dbg("External content")
    local status, extdata = readExternalData(dis)
    if status then
      desc["externalData"] = extdata
    end
  else
    dbg("Serial content")
    local status, serdata = readExternalData(dis)
    if status then
      desc["externalData"] = serdata
      local status, data =parseExternalData(desc)
      if status then
        desc['externalData'] = data
      end
    end
  end
  return status, desc

end

-- Attempts to read some object-data, at least remove the block
-- header. This method returns the external data in 'raw' form,
-- since it is up to each class to define an readExternal method
function readExternalData(dis)
  local  data = {}
  while dis.bReader:bufferSize() > 0 do
    local status, tc= dis:readByte()
    if not status then
      return doh("Could not read external data")
    end
    dbg("readExternalData: %s", RMIUtils.tcString(tc))
    local status, len, content
    if tc == TC.TC_BLOCKDATA then
      status, len = dis:readByte()
      status, content = dis.bReader:skip(len)
      --print(makeStringReadable(content))
      dbg("Read external data (%d bytes): %s " ,len, content)
      --local object = ExternalClassParsers['java.rmi.server.RemoteObject'](dis)
      --print(object)
      return status, content
    elseif tc == TC.TC_BLOCKDATALONG then
      status, len = dis:readUnsignedInt()
      status, content = dis.bReader:skip(len)
      return status, content
    elseif tc == TC.TC_ENDBLOCKDATA then
      --noop
    else
      return doh("Got unexpected field in readExternalData: %s ", RMIUtils.tcString(tc))
    end
  end
end

----
-- ExternalClassParsers : External Java Classes
-- This 'class' contains information about certain specific java classes,
-- such as UnicastRef, UnicastRef2. After such an object has been read by
-- the object serialization protocol, it will contain a lump of data which is
-- in 'external' form, and needs to be read in a way which is specific for the class
-- itself. This class contains the implementations for reading out the
-- 'goodies' of e.g UnicastRef, which contain important information about
-- where another RMI-socket is listening and waiting for someone to connect.
ExternalClassParsers = {
  ---
  --@see sun.rmi.transport.tcp.TCPEndpoint
  --@see sun.rmi.server.UnicastRef
  --@see sun.rmi.server.UnicastRef2
  UnicastRef = function(dis)
    local sts_host, host = dis:readUTF()
    if not sts_host then
      return doh("Parsing external data, could not read host (UTF)")
    end
    local sts_port, port = dis:readUnsignedInt()
    if not sts_port then
      return doh("Parsing external data, could not read port (int)")
    end
    dbg("a host: %s, port %d", host, port)
    return true, ("@%s:%d"):format(host,port)
  end,
  ---
  --@see sun.rmi.transport.tcp.TCPEndpoint
  --@see sun.rmi.server.UnicastRef
  --@see sun.rmi.server.UnicastRef2
  UnicastRef2 = function(dis)
    local sts_form, form = dis:readByte()
    if not sts_form then
      return doh("Parsing external data, could not read byte")
    end
    if not (form == 0 or form == 1) then-- FORMAT_HOST_PORT or  FORMAT_HOST_PORT_FACTORY
      return doh("Invalid endpoint format")
    end
    local sts_host, host = dis:readUTF()
    if not sts_host then
      return doh("Parsing external data, could not read host (UTF)")
    end
    local sts_port, port = dis:readUnsignedInt()
    if not sts_port then
      return doh("Parsing external data, could not read port (int)")
    end
    dbg("b host: %s, port %d", host, port)
    if form == 0 then
      return true, ("@%s:%d"):format(host,port)
    end
    -- for FORMAT_HOST_PORT_FACTORY, there's an object left to read
    local sts_object, object = readObject0(dis)
    return true, ("@%s:%d"):format(host,port)
    --return true, {host = host, port = port, factory = object}
  end
}
--@see java.rmi.server.RemoteObject:readObject()
ExternalClassParsers['java.rmi.server.RemoteObject'] = function(dis)
  local status, refClassName = dis:readUTF()
  if not status then return doh("Parsing external data, could not read classname (UTF)") end
  if #refClassName == 0 then
    local status, ref = readObject0(dis)
    return status, ref
  end
  dbg("Ref class name: %s ", refClassName)
  local parser = ExternalClassParsers[refClassName]

  if parser == nil then
    return doh("No external class reader for %s" , refClassName)
  end

  local status, object = parser(dis)
  return status, object
end

-- Attempts to parse the externalized data of an object.
--@return status, the object data
function parseExternalData(j_object)

  if j_object == nil then
    return doh("parseExternalData got nil object")
  end

  local className = j_object:getName()

  -- Find parser for the object, move up the hierarchy
  local obj = j_object
  local parser = nil
  while(className  ~= nil) do
    parser = ExternalClassParsers[className]
    if parser ~= nil then break end

    obj = obj:getSuperClass()
    if obj== nil then break  end-- No more super classes
    className = obj:getName()
  end

  if parser == nil then
    return doh("External reader for class %s is not implemented", tostring(className))
  end
  -- Read the actual object, start by creating a new dis based on the data-string
  local dis = JavaDIS:new(BufferedReader:new(nil,j_object.externalData))
  local status, object = parser(dis)
  if not status then
    return doh("Could not parse external data")
  end
  return true, object
end

-- Helper function to display data
-- returns the string with all non-printable chars
-- coded as hex
function makeStringReadable(data)
  return data:gsub("[\x00-\x1f\x7f-\xff]", function (x)
      return ("\\x%02x"):format(x:byte())
    end)
end

function readNonProxyDesc(dis)
  dbg("-- entering readNonProxyDesc--")
  local j_class = JavaClass:new()
  local status, classname = dis:readUTF()
  if not status then return doh( "Could not read data" ) end
  j_class:setName(classname)

  local status, serialID = dis:readLongAsHexString()
  if not status then return doh("Could not read data") end
  j_class:setSerialID(serialID)

  dbg("Set serial ID to %s", tostring(serialID))

  local status, flags = dis:readByte()
  if not status then return doh("Could not read data") end
  j_class:setFlags(flags)


  local status, fieldCount = dis:readShort()
  if not status then return doh( "Could not read data") end

  dbg("Fieldcount %d", fieldCount)

  local fields = {}
  for i =0, fieldCount-1,1 do
    local status, fieldDesc = readFieldDesc(dis)
    j_class:addField(fieldDesc)
    -- Need to store in list, the field values need to be read
    -- after we have finished reading the class description
    -- hierarchy
    table.insert(fields,fieldDesc)
  end
  local status, customStrings = skipCustomData(dis)
  if status and customStrings ~= nil and #customStrings > 0 then
    j_class:setCustomData(customStrings)
  end

  local _,superDescriptor = readClassDesc(dis)

  j_class:setSuperClass(superDescriptor)
  dbg("Superclass read, now reading %i field values", #fields)
  --Read field values
  for i=1, #fields, 1 do
    local status, fieldType = dis:readByte()
    local value = nil
    if ( TypeDecoders[fieldType] ) then
      status, value= TypeDecoders[fieldType](dis)
    else
      dbg("error reading".. RMIUtils.tcString(fieldType))
      return
    end
    dbg("Read fieldvalue ".. tostring(value) .. " for field ".. tostring(fields[i]))
    fields[i]:setValue(value)
  end
  dbg("-- leaving readNonProxyDesc--")
  return true, j_class


end

function readProxyDesc(dis)
  dbg("-- in readProxyDesc--")
  local interfaces = ''
  local superclass = nil
  local status, ifaceNum= dis:readInt()
  if not status then return doh("Could not read data") end
  --dbg("# interfaces: %d" , ifaceNum)
  while ifaceNum > 0 do
    local status, iface = dis:readUTF()
    if not status then return doh( "Could not read data") end
    --table.insert(interfaces, iface)
    interfaces = interfaces .. iface ..', '
    dbg("Interface: %s " ,iface)
    ifaceNum = ifaceNum-1
  end

  local j_class = JavaClass:new()

  local status, customStrings = skipCustomData(dis)
  if status and customStrings ~= nil and #customStrings > 0 then
    j_class:setCustomData(customStrings)
  end

  local _,superDescriptor = readClassDesc(dis)


  --print ("superdescriptor", superDescriptor)
  j_class:setSuperClass(superDescriptor)
  j_class:setInterfaces(interfaces)

  dbg("-- leaving readProxyDesc--")
  return true, j_class

end
--
-- Skips over all block data and objects until TC_ENDBLOCKDATA is
-- encountered.
-- @see java.io.ObjectInputStream.skipCustomData()
--@return status
--@return any strings found while searching
function skipCustomData(dis)
  -- If we come across something interesting, just put it into
  -- the returnData list
  local returnData = {}
  while true do
    local status, p = dis:readByte()
    if not status then
      return doh("Could not read data")
    end

    if not status then return doh("Could not read data") end
    dbg("skipCustomData read %s", RMIUtils.tcString(p))

    if p == TC.TC_BLOCKDATA or p == TC.TC_BLOCKDATALONG then
      dbg("continuing")
      --return
    elseif p == TC.TC_ENDBLOCKDATA then
      return true, returnData
    else
      -- In the java impl, this is a function called readObject0. We just
      -- use the read null, otherwise error
      if p == TC.TC_NULL then
        -- No op, already read the byte, continue reading
      elseif p == TC.TC_STRING then
        --dbg("A string is coming!")
        local status,  str = dis:readUTF()
        if not status then
          return doh("Could not read data")
        end
        dbg("Got a string, but don't know what to do with it! : %s",str)
        -- Object serialization is a bit messy. I have seen the
        -- classpath being sent over a customdata-field, so it is
        -- definitely interesting. Quick fix to get it showing
        -- is to just stick it onto the object we are currently at.
        -- So, just put the string into the returnData and continue
        table.insert(returnData, str)
      else
        return doh("Not implemented in skipcustomData:: %s", RMIUtils.tcString(p))
      end
    end
  end
end

function readFieldDesc(dis)
  -- fieldDesc:
  --   primitiveDesc
  --   objectDesc
  -- primitiveDesc:
  --   prim_typecode fieldName
  -- objectDesc:
  --   obj_typecode fieldName className1
  --   prim_typecode:
  --   `B'  // byte
  --   `C'  // char
  --   `D'  // double
  --   `F'  // float
  --   `I'  // integer
  --   `J'  // long
  --   `S'  // short
  --   `Z'  // boolean
  -- obj_typecode:
  --   `[`  // array
  --   `L'  // object
  local j_field = JavaField:new()

  local status, c = dis:readByte()
  if not status then return doh("Could not read data") end

  local char = string.char(c)

  local status, name = dis:readUTF()
  if not status then return doh("Could not read data") end

  local fieldType = ('primitive type: (%s) '):format(char)
  dbg("Fieldtype, char = %s, %s", tostring(fieldType), tostring(char))
  if char == 'L' or char == '['  then
    -- These also have classname which tells the type
    -- on the field
    local status, fieldclassname = readTypeString(dis)
    if not status then return doh("Could not read data") end
    if char == '[' then
      fieldType = fieldclassname .. " []"
    else
      fieldType = fieldclassname
    end
  end

  if not status then
    return false, fieldType
  end

  dbg("Field description: name: %s, type: %s", tostring(name), tostring(fieldType))

  j_field:setType(fieldType)
  j_field:setName(name)
  -- setType = function( self, typ ) self.type = typ end,
  -- setSignature = function( self, sig ) self.signature = sig end,
  -- setName = function( self, name ) self.name = name end,
  -- setObjectType = function( self, ot ) self.object_type = ot end,
  -- setReference = function( self, ref ) self.ref = ref end,

  dbg("Created java field:".. tostring(j_field))

  return true, j_field

end

function readTypeString(dis)
  local status, tc = dis:readByte()
  if not status then return doh("Could not read data") end
  if  tc == TC.TC_NULL then
    return true, nil
  elseif tc== TC.TC_REFERENCE then
    return doh("Not implemented, readTypeString(TC_REFERENCE)");
  elseif tc == TC.TC_STRING then
    return dis:readUTF()
  elseif tc == TC.TC_LONGSTRING then
    --TODO, add this (will throw error as is)
    return dis:readLongUTF()
  end
end

TypeDecoders =
{
  [TC.TC_ARRAY] = readArray,
  [TC.TC_CLASSDESC] = readClassDesc,
  [TC.TC_STRING] = readString,
  [TC.TC_OBJECT] = readOrdinaryObject,
}

---
-- Registry
-- Class to represent the RMI Registry.
--@usage:
-- registry = rmi.Registry:new()
-- status, data = registry:list()
Registry ={
  new = function  (self,host, port)
    local o ={}   -- create object
    setmetatable(o, self)
    self.__index = self -- DIY inheritance
    -- Hash code for sun.rmi.registry.RegistryImpl_Stub, which we are invoking :
    -- hex: 0x44154dc9d4e63bdf, dec: 4905912898345647071
    self.hash = '44154dc9d4e63bdf'
    -- RmiRegistry object id is 0
    self.objId = 0
    o.host = host
    o.port = port
    return o
  end
}
-- Connect to the remote registry.
--@return status
--@return error message
function Registry:_handshake()
  local out = RmiDataStream:new()
  local status, err = out:connect(self.host,self.port)

  if not status then
    return doh("Registry connection failed: %s", tostring(err))
  end
  dbg("Registry connection OK "..tostring(out.bsocket) )
  self.out = out
  return true
end
---
-- List the named objects in the remote RMI registry
--@return status
--@return a table of strings , or error message
function Registry:list()
  if not self:_handshake() then
    return doh("Handshake failed")
  end
  -- Method list() is op number 1
  return self.out:invoke(self.objId, self.hash,1)
end
---
-- Perform a lookup on an object in the Registry,
-- takes the name which is bound in the registry
-- as argument
--@return status
--@return JavaClass-object
function Registry:lookup(name)
  self:_handshake()
  -- Method lookup() is op number 2
  -- Takes a string as arguments
  local a = Arguments:new()
  a:addString(name)
  return self.out:invoke(self.objId, self.hash,2, a)
end
----
-- Arguments class
-- This class is meant to handle arguments which is sent to a method invoked
-- remotely. It is mean to contain functionality to add java primitive datatypes,
-- such as pushInt, pushString, pushLong etc. All of these are not implemented
-- currently
--@usage: When invoking a remote method
-- use this class in this manner:
--  Arguments a = Arguments:new()
--  a:addString("foo")
--  datastream:invoke{objNum=oid, hash=hash, opNum = opid, arguments=a}
--  ...
--
Arguments = {

  new = function  (self,o)
    o = o or {}   -- create object if user does not provide one
    setmetatable(o, self)
    self.__index = self -- DIY inheritance
    -- We use a buffered socket just to be able to use a javaDOS for writing
    self.dos = JavaDOS:new(BufferedWriter:new())
    return o
  end,
  addString = function(self, str)
    self.dos:writeByte(TC.TC_STRING)
    self.dos:writeUTF(str)
  end,
  addRaw = function(self, str)
    self.dos:write(str)
  end,
  getData = function(self)
    local _, res = self.dos:flush()
    return res
  end
}


---
-- RMIUtils class provides some some codes and definitions from Java
-- There are three types of output messages: Call, Ping  and DgcAck.
-- A Call encodes a method invocation. A Ping  is a transport-level message
-- for testing liveness of a remote virtual machine.
-- A DGCAck is an acknowledgment directed to a
-- server's distributed garbage collector that indicates that remote objects
-- in a return value from a server have been received by the client.

RMIUtils = {

  -- Indicates a Serializable class defines its own writeObject method.
  SC_WRITE_METHOD = 0x01,
  -- Indicates Externalizable data written in Block Data mode.
  SC_BLOCK_DATA = 0x08,
  -- Bit mask for ObjectStreamClass flag. Indicates class is Serializable.
  SC_SERIALIZABLE = 0x02,
  --Bit mask for ObjectStreamClass flag. Indicates class is Externalizable.
  SC_EXTERNALIZABLE = 0x04,
  --Bit mask for ObjectStreamClass flag. Indicates class is an enum type.
  SC_ENUM = 0x10,

  flagsToString = function(flags)
    local retval = ''
    if ( (flags & RMIUtils.SC_WRITE_METHOD) ~= 0) then
      retval = retval .. " WRITE_METHOD"
    end
    if ( (flags & RMIUtils.SC_BLOCK_DATA) ~= 0) then
      retval = retval .. " BLOCK_DATA"
    end
    if ( (flags & RMIUtils.SC_EXTERNALIZABLE) ~= 0) then
      retval = retval .. " EXTERNALIZABLE"
    end
    if ( (flags & RMIUtils.SC_SERIALIZABLE) ~= 0) then
      retval = retval .. " SC_SERIALIZABLE"
    end
    if ( (flags & RMIUtils.SC_ENUM) ~= 0) then
      retval = retval .. " SC_ENUM"
    end
    return retval
  end,
  tcString = function (constant)
    local x = TC.Strings[constant] or "Unknown code"
    return ("%s (0x%x)"):format(x,tostring(constant))

  end,

}

local RMIMessage = {
  Call = 0x50,
  Ping = 0x52,
  DgcAck= 0x54,
}
STREAM_MAGIC =  0xaced
STREAM_VERSION = 5

baseWireHandle = 0x7E0000

return _ENV;

Youez - 2016 - github.com/yon3zu
LinuXploit