ANTLR for Python: Name 'Lexer' is not defined - python-2.7

I just executed the script here
https://github.com/antlr/antlr4/blob/master/doc/python-target.md
$ antlr4 -Dlanguage=Python2 Hello.g4
and I successfully got the files:
`12/05/2022 07:18 AM 250 Hello.interp`
`12/05/2022 07:18 AM 31 Hello.tokens`
`12/05/2022 07:18 AM 990 HelloLexer.interp`
`12/05/2022 07:18 AM 1,711 HelloLexer.py`
`12/05/2022 07:18 AM 31 HelloLexer.tokens`
`12/05/2022 07:18 AM 392 HelloListener.py`
`12/05/2022 07:18 AM 2,351 HelloParser.py`
`11/29/2022 02:42 PM 544 main.py`
But when I run the main.py, I got an error message
NameError: name 'Lexer' is not defined
Where is the Lexer definition in ANTLR for Python?
How to overcome the error?

Related

'no python application found' in Django

I tried to deploy my Django project on server with uwsgi.
I can initial uwsgi with uwsgi --ini conf/uwsgi.ini
But when I tried to visit the website, I got this error
--- no python application found, check your startup logs for errors ---
[pid: 11228|app: -1|req: -1/1] 127.0.0.1 () {46 vars in 946 bytes} [Mon Nov 28 17:06:37 2022] GET / => generated 21 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 83 bytes (0 switches on core 0)
I put my repo at https://github.com/dolphinfafa/MyLife
Anyone knows how to resolve this?

Snort Config: PCRE Matching across TCP Packets

I am working with my Security Onion and at the moment all the longer PCRE is not working, because the rules and the regex is not applied to the TCP stream but only to single packets.
My Snort.conf should have everything enabled:
# Target-based IP defragmentation. For more inforation, see README.frag3
preprocessor frag3_global: max_frags 65536
preprocessor frag3_engine: policy windows detect_anomalies overlap_limit 10 min_fragment_length 100 timeout 180
# Target-Based stateful inspection/stream reassembly. For more inforation, see README.stream5
preprocessor stream5_global: track_tcp yes, \
track_udp yes, \
track_icmp no, \
max_tcp 262144, \
max_udp 131072, \
max_active_responses 2, \
min_response_seconds 5
preprocessor stream5_tcp: log_asymmetric_traffic no, policy windows, \
detect_anomalies, require_3whs 180, \
overlap_limit 10, small_segments 3 bytes 150, timeout 180, \
ports client 21 22 23 25 42 53 79 109 110 111 113 119 135 136 137 139 143 \
161 445 513 514 587 593 691 1433 1521 1741 2100 3306 6070 6665 6666 6667 6668 6669 \
7000 8181 32770 32771 32772 32773 32774 32775 32776 32777 32778 32779, \
ports both 80 81 311 383 443 465 563 591 593 636 901 989 992 993 994 995 1220 1414 1830 2301 2381 2809 3037 3128 3702 4343 4848 5250 6988 7907 7000 7001 7144 7145 7510 7802 7777 7779 \
7801 7900 7901 7902 7903 7904 7905 7906 7908 7909 7910 7911 7912 7913 7914 7915 7916 \
7917 7918 7919 7920 8000 8008 8014 8028 8080 8085 8088 8090 8118 8123 8180 8243 8280 8300 8800 8888 8899 9000 9060 9080 9090 9091 9443 9999 11371 34443 34444 41080 50002 55555
preprocessor stream5_udp: timeout 180
Now I got a node.js server up with a simple XML file (I made it a little bit shorter):
<?xml version="1.0" encoding="UTF-8"?>
<saml2p:Response Destination="http://localhost:8080/sp/saml/index.html"
ID="_28940080d39ea1191d9910414147f372"
InResponseTo="_15b217492a05e534df8539c7a84014cd"
IssueInstant="2018-07-24T16:04:13.830Z" Version="2.0"
xmlns:saml2p="urn:oasis:names:tc:SAML:2.0:protocol"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:oasis:names:tc:SAML:2.0:protocol">
<saml2:Issuer xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion">eLearning SAML SSO IdP</saml2:Issuer>
<saml2p:Status>
<saml2p:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success"/>
</saml2p:Status>
<saml2:Assertion ID="_evil_assertion_ID"
IssueInstant="2018-07-24T16:04:13.831Z" Version="2.0"
xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:oasis:names:tc:SAML:2.0:protocol">
<saml2:Issuer>eLearning SAML SSO IdP</saml2:Issuer>
<saml2:Subject>
<saml2:NameID Format="urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress">xmluser</saml2:NameID>
[..........................]
</saml2:AuthnContext>
</saml2:AuthnStatement>
</saml2:Assertion>
</saml2p:Response>
A rule matching only the content:"saml2p:response" or a small regex like pcre:"/saml2p:Response/smi" is working without problem, but a rule with a longer regex is not matching the pattern.
I made my rule as generic as possible:
alert tcp any any -> any any (msg:"ET WEB_SERVER SAML XSW3 Attack, Possible Signature Wrapping Attack v15"; pcre:"/saml2p:Response.*?/saml2p:Response/smi"; reference:url,https://www.usenix.org/system/files/conference/usenixsecurity12/sec12-final91.pdf; classtype:web-application-attack; sid:200000120; rev:1;)
edit: I have also tried this rule with all versions of flow:from_server,established; (to_server, from_client, to_client). None of them is working for me. But when I cut down the xml to a size which fits in one packet, all rules are firing!
The Regex pcre:"/saml2p:Response.*?/saml2p:Response/smi" should match everything from the first response tag to the closing response tag, but whenever it is splitted into different TCP Packets the regex is not matching.
Do i miss anything?
Thanks for your help!

Clojure - add file to the classpath

How do I add resources (preferably programmatically) to the classpath of my program ?
I am using compojure.route.resources like the following :
A route for serving resources on the classpath. Accepts the following
keys: :root - the root prefix path of the resources, defaults
to 'public' :mime-types - an optional map of file extensions to mime
types
(defroutes routes
(resources "/js" {:root "js"})
(resources "/css" {:root "css"}))
Now I would like to add files to be served, but I don't know where to generate them.
Note : in case it matters, I am using boot and the example is taken from this template.
In regular boot based project, you can have a resources folder at the root:
-rw-r--r--# 1 niko staff 173 Dec 18 10:19 boot.properties
-rw-r--r--# 1 niko staff 2796 Dec 30 09:55 build.boot
drwxr-xr-x# 17 niko staff 578 Dec 30 10:49 resources
drwxr-xr-x# 4 niko staff 136 Nov 16 09:52 src
drwxr-xr-x# 17 niko staff 578 Jan 14 11:50 target
In that folder you can create the css and the js folder and include your files there:
drwxr-xr-x# 5 niko staff 170 Dec 14 15:33 resources/css/
drwxr-xr-x# 4 niko staff 136 Nov 30 18:01 resources/js/

The page cannot be displayed because an internal server error has occurred

I have a site deployed on azure with django. I have been working on the site for about 6 months and it was working fine. Today all of a sudden the site is not working any more.
The only output I am getting is - "The page cannot be displayed because an internal server error has occurred."
I have the same django code working perfectly on localhost. My azure account has 2 django sites running. Each site is deployed from 2 separate branches from a git repo. Both of them are down.
I tried deploying earlier deployments on azure. it is still showing the same error.
I have also tried setting debug to true on production server. Same results. It seems django is not even being loaded.
My azure account shows a lot of "html server error", when I check under the monitor tab for the site.
What is the problem and how do I solve it? Is a django not loading problem or an azure problem? How do I debug this?
Edit - error log from ftp - logfiles/http/rawlogs
# date time s-sitename cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User-Agent) cs(Cookie) cs(Referer) cs-host sc-status sc-substatus sc-win32-status sc-bytes cs-bytes time-taken
2013-07-19 13:20:30 MAKEYSTREET GET /robots.txt X-ARR-LOG-ID=dbb6383f-5342-4fe4-a419-e3f5f373a8f8 80 - 66.249.74.139 Mozilla/5.0+(compatible;+Googlebot/2.1;++http://www.google.com/bot.html) - - www.makeystreet.com 500 0 0 245 416 3484
2013-07-19 13:34:28 MAKEYSTREET GET / X-ARR-LOG-ID=b4c37c5c-46b3-4ff5-9ae7-e0f18f04b404 80 - 10.21.91.242 Mozilla/5.0+(X11;+Linux+i686)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Ubuntu+Chromium/28.0.1500.52+Chrome/28.0.1500.52+Safari/537.36 ARRAffinity=cf6d46f9fadcc9b088669ec23467baf056a50376566d6aacdbea46e06b6acfa5;+WAWebSiteSID=6c2bf64764594b7ca90e2b539b89b9e6;+sessionid=rhvhu9ibb814v1vwqe3nahkkt1lw0yvu;+csrftoken=gO1x5Vm6kzDRKhmbyjbUuVqWKLUjW3Qy;+_ga=GA1.2.1129966823.1374156576 - makeystreet.com 500 0 0 269 897 3546
2013-07-19 13:34:28 MAKEYSTREET GET /favicon.ico X-ARR-LOG-ID=d918daf9-815e-4ef7-8360-525c9c31506c 80 - 10.21.91.242 Mozilla/5.0+(X11;+Linux+i686)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Ubuntu+Chromium/28.0.1500.52+Chrome/28.0.1500.52+Safari/537.36 ARRAffinity=cf6d46f9fadcc9b088669ec23467baf056a50376566d6aacdbea46e06b6acfa5;+WAWebSiteSID=6c2bf64764594b7ca90e2b539b89b9e6;+sessionid=rhvhu9ibb814v1vwqe3nahkkt1lw0yvu;+csrftoken=gO1x5Vm6kzDRKhmbyjbUuVqWKLUjW3Qy;+_ga=GA1.2.1129966823.1374156576 - makeystreet.com 500 0 0 269 864 93
2013-07-19 14:04:47 MAKEYSTREET GET /robots.txt X-ARR-LOG-ID=1b516136-4a39-4543-b9a4-540ce1fce959 80 - 66.249.74.139 Mozilla/5.0+(compatible;+Googlebot/2.1;++http://www.google.com/bot.html) - - www.makeystreet.com 500 0 0 245 416 3515
2013-07-19 14:05:54 MAKEYSTREET GET / X-ARR-LOG-ID=7dc870f8-a7d4-4701-8b75-042789a362cf 80 - 122.166.237.111 Mozilla/5.0+(Windows+NT+6.1;+WOW64;+rv:22.0)+Gecko/20100101+Firefox/22.0 - - www.makeystreet.com 500 0 0 245 440 187
2013-07-19 14:05:54 MAKEYSTREET GET /favicon.ico X-ARR-LOG-ID=64681a43-c47e-4aea-982d-bd3dace9b19e 80 - 122.166.237.111 Mozilla/5.0+(Windows+NT+6.1;+WOW64;+rv:22.0)+Gecko/20100101+Firefox/22.0 ARRAffinity=cf6d46f9fadcc9b088669ec23467baf056a50376566d6aacdbea46e06b6acfa5;+WAWebSiteSID=2e0ff00f9fd84e28ac6b757c93b43b23 - www.makeystreet.com 500 0 0 245 595 62
2013-07-19 14:06:10 MAKEYSTREET GET / X-ARR-LOG-ID=db1870ec-3b2a-4449-ac13-05ab67ffa212 80 - 122.166.237.111 Mozilla/5.0+(Windows+NT+6.1;+WOW64;+rv:22.0)+Gecko/20100101+Firefox/22.0 ARRAffinity=cf6d46f9fadcc9b088669ec23467baf056a50376566d6aacdbea46e06b6acfa5;+WAWebSiteSID=2e0ff00f9fd84e28ac6b757c93b43b23 - www.makeystreet.com 500 0 0 245 573 109
2013-07-19 14:21:55 MAKEYSTREET GET / X-ARR-LOG-ID=4e72fbec-ff2e-4068-b9fe-0a536718e8c7 80 - 10.21.91.242 Mozilla/5.0+(X11;+Linux+i686)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Ubuntu+Chromium/28.0.1500.52+Chrome/28.0.1500.52+Safari/537.36 ARRAffinity=cf6d46f9fadcc9b088669ec23467baf056a50376566d6aacdbea46e06b6acfa5;+WAWebSiteSID=6c2bf64764594b7ca90e2b539b89b9e6;+sessionid=rhvhu9ibb814v1vwqe3nahkkt1lw0yvu;+csrftoken=gO1x5Vm6kzDRKhmbyjbUuVqWKLUjW3Qy;+_ga=GA1.2.1129966823.1374156576 - makeystreet.com 500 0 0 245 887 3515
2013-07-19 14:21:56 MAKEYSTREET GET /favicon.ico X-ARR-LOG-ID=ee05ce88-08cc-4837-94a4-4ef0326a46be 80 - 10.21.91.242 Mozilla/5.0+(X11;+Linux+i686)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Ubuntu+Chromium/28.0.1500.52+Chrome/28.0.1500.52+Safari/537.36 ARRAffinity=cf6d46f9fadcc9b088669ec23467baf056a50376566d6aacdbea46e06b6acfa5;+WAWebSiteSID=6c2bf64764594b7ca90e2b539b89b9e6;+sessionid=rhvhu9ibb814v1vwqe3nahkkt1lw0yvu;+csrftoken=gO1x5Vm6kzDRKhmbyjbUuVqWKLUjW3Qy;+_ga=GA1.2.1129966823.1374156576 - makeystreet.com 500 0 0 269 864 124

Django app works via manage.py runserver but page rendered via mod_uwsgi fails to refer to static elements

I am at the end of my rope here... and plan to start digging into Django source code to figure this out.
I have a Django app that has been created in the standard fashion via start project. So far I have been testing it via "python manage.py runserver 8081".
Now I am trying to put this behind Nginx using mod_uwsgi.
So I test it using the excellent instructions over here.
My ini file looks as follows:
uwsgi]
chdir=<path_to_my_project>
module=<application>.wsgi:application
pidfile=/tmp/<pid_file_name>
max-requests=5000
daemonize=/var/log/uwsgi/<log_file_name>
env=DJANGO_SETTINGS_MODULE=<application>.settings
http-socket=127.0.0.1:50000
So I start the app using:
uwsgi --ini uwsgi.ini
All seems to look good:
Log file at "/var/log/uwsgi/" created: Looks good.
Directory is changed: Looks good. Log file indicates so.
Module is loaded: Assume that it has... I don't see any error message in the logs.
pidfile is created: Looks good. I do see the correct PID number in the file.
Tested the closing of the process via SIGINT.
Listening at http-socket: Looks good.
PROBLEM:
When I hit the site via http://site_url; I get the HTML page in my browser. But none of the CSS styles are reflected. Also, none of my java-script functions are executed. So not sure what is amiss.
FYI: I noticed the following lines in the log:
[pid: 15730|app: 0|req: 7/7] 127.0.0.1 () {36 vars in 696 bytes} [Thu Apr 25 16:40:50 2013] GET / => generated 11774 bytes in 2 msecs (HTTP/1.1 200) 1 headers in 59 bytes (1 switches on core 0)
[pid: 15730|app: 0|req: 8/8] 127.0.0.1 () {36 vars in 710 bytes} [Thu Apr 25 16:40:50 2013] GET /static/jquery/jquery-1.9.1.min.js => generated 2874 bytes in 3 msecs (HTTP/1.1 404) 1 headers in 51 bytes (1 switches on core 0)
[pid: 15730|app: 0|req: 9/9] 127.0.0.1 () {36 vars in 727 bytes} [Thu Apr 25 16:40:50 2013] GET /static/bootstrap/css/bootstrap.css => generated 2877 bytes in 3 msecs (HTTP/1.1 404) 1 headers in 51 bytes (1 switches on core 0)
[pid: 15730|app: 0|req: 10/10] 127.0.0.1 () {36 vars in 716 bytes} [Thu Apr 25 16:40:50 2013] GET /static/bootstrap/js/bootstrap.min.js => generated 2883 bytes in 3 msecs (HTTP/1.1 404) 1 headers in 51 bytes (1 switches on core 0)
[pid: 15730|app: 0|req: 11/11] 127.0.0.1 () {32 vars in 570 bytes} [Thu Apr 25 16:40:50 2013] GET /favicon.ico => generated 2808 bytes in 3 msecs (HTTP/1.1 404) 1 headers in 51 bytes (1 switches on core 0)
[pid: 15730|app: 0|req: 12/12] 127.0.0.1 () {36 vars in 696 bytes} [Thu Apr 25 16:40:51 2013] GET / => generated 11774 bytes in 2 msecs (HTTP/1.1 200) 1 headers in 59 bytes (1 switches on core 0)
[pid: 15730|app: 0|req: 13/13] 127.0.0.1 () {36 vars in 710 bytes} [Thu Apr 25 16:40:51 2013] GET /static/jquery/jquery-1.9.1.min.js => generated 2874 bytes in 3 msecs (HTTP/1.1 404) 1 headers in 51 bytes (1 switches on core 0)
[pid: 15730|app: 0|req: 14/14] 127.0.0.1 () {36 vars in 727 bytes} [Thu Apr 25 16:40:51 2013] GET /static/bootstrap/css/bootstrap.css => generated 2877 bytes in 3 msecs (HTTP/1.1 404) 1 headers in 51 bytes (1 switches on core 0)
[pid: 15730|app: 0|req: 15/15] 127.0.0.1 () {36 vars in 716 bytes} [Thu Apr 25 16:40:51 2013] GET /static/bootstrap/js/bootstrap.min.js => generated 2883 bytes in 3 msecs (HTTP/1.1 404) 1 headers in 51 bytes (1 switches on core 0)
[pid: 15730|app: 0|req: 16/16] 127.0.0.1 () {32 vars in 570 bytes} [Thu Apr 25 16:40:51 2013] GET /favicon.ico => generated 2808 bytes in 3 msecs (HTTP/1.1 404) 1 headers in 51 bytes (1 switches on core 0)
Is there some additional config that I seem to have missed?
Would greatly appreciate your time and input. I will leave a solution in case I find one.
Best...
You may want to check the section on the django docs about serving static files. The rules for mod_wsgi apply to mod_uwsgi. A more easy approach is configuring uWSGI to serve static files:
http://uwsgi-docs.readthedocs.org/en/latest/StaticFiles.html
Check the part about offloading if your site is pretty loaded
Generally avoid using django for serving static files
I am not using nginx but Apache, running mod_wsgi.
There I have the possibility to use
Alias /static/ /var/www/django-project/static/
All files are in my directory and accesaible at http://example.com/static/.
So maybe you can do the same with nginx.
Edit:
This skips the process of wsgi/cgi/uwsgi and allows the http daemon to handle the static files directly. There is no need for python to parse these kind of requests - because they're only accessing static files.